Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Use NonZero
Ilya03d737b759bc
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx b/apps/desktop/src/routes/(window-chrome)/settings/general.tsxindex fcda2cd2c..c4b21dd44 100644--- a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx+++ b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx@@ -743,9 +743,9 @@ function DefaultProjectNameCard(props: {size="sm"variant="dark"disabled={isSaveDisabled()}- onClick={() => {- props.onChange(inputValue() ?? null);- updatePreview();+ onClick={async () => {+ await props.onChange(inputValue() ?? null);+ await updatePreview();}}>Savediff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rsindex f65765cf5..4928f787f 100644--- a/crates/utils/src/lib.rs+++ b/crates/utils/src/lib.rs@@ -1,4 +1,10 @@-use std::{borrow::Cow, future::Future, path::PathBuf, sync::LazyLock};+use std::{+ borrow::Cow,+ future::Future,+ num::{NonZero, NonZeroI16, NonZeroI32},+ path::PathBuf,+ sync::LazyLock,+};use aho_corasick::{AhoCorasickBuilder, MatchKind};use tracing::Instrument;@@ -47,13 +53,18 @@ pub fn ensure_unique_filename(base_filename: &str,parent_dir: &std::path::Path,) -> Result<String, String> {- ensure_unique_filename_with_attempts(base_filename, parent_dir, 20)+ ensure_unique_filename_with_attempts(+ base_filename,+ parent_dir,+ // SAFETY: 20 is non zero+ unsafe { NonZero::new_unchecked(50) },+ )}pub fn ensure_unique_filename_with_attempts(base_filename: &str,parent_dir: &std::path::Path,- attempts: i32,+ attempts: NonZeroI32,) -> Result<String, String> {let initial_path = parent_dir.join(base_filename);@@ -73,6 +84,7 @@ pub fn ensure_unique_filename_with_attempts((base_filename, String::new())};+ let max_attemps = attempts.get();let mut counter = 1;loop {@@ -91,7 +103,7 @@ pub fn ensure_unique_filename_with_attempts(counter += 1;// prevent infinite loop- if counter > attempts {+ if counter > max_attemps {return Err("Too many filename conflicts, unable to create unique filename".to_string(),);@@ -162,10 +174,6 @@ pub fn ensure_unique_filename_with_attempts(/// // 12-hour format with full names/// DDDD, MMMM DD at h:mm A → %A, %B %d at %-I:%M %p/// // Output: "Monday, January 15 at 2:30 PM"-///-/// // ISO week date-/// YYYY-Www-D → %G-W%V-%u-/// // Output: "2025-W03-1"/// ```////// # Note