From 3aa4a29191a5e69a396c98e48cda40ce1a5d3057 Mon Sep 17 00:00:00 2001 From: Daniel Elskamp Date: Wed, 1 Jul 2026 10:18:57 +0200 Subject: [PATCH] style(src-tauri): rustfmt storage.rs and update.rs The recent lazy-loading feature commits landed unformatted, turning the CI `cargo fmt --all --check` gate red on main. Apply rustfmt; no logic changes. Co-Authored-By: Claude Opus 4.8 --- src-tauri/src/storage.rs | 38 +++++++++++++++++++++++++++++--------- src-tauri/src/update.rs | 35 ++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/src-tauri/src/storage.rs b/src-tauri/src/storage.rs index 3c434cd..2991a8c 100644 --- a/src-tauri/src/storage.rs +++ b/src-tauri/src/storage.rs @@ -114,7 +114,10 @@ pub fn note_preview(html: &str) -> String { let s = html.trim_start(); let inner = match s.strip_prefix('<') { Some(rest) => { - let name: String = rest.chars().take_while(|c| c.is_ascii_alphanumeric()).collect(); + let name: String = rest + .chars() + .take_while(|c| c.is_ascii_alphanumeric()) + .collect(); match (name.is_empty(), s.find('>')) { (false, Some(gt)) => { let body = &s[gt + 1..]; @@ -238,7 +241,9 @@ impl Store { /// The full HTML content of one note, or `None` if it doesn't exist. pub fn load_note_content(&self, id: &str) -> rusqlite::Result> { - let mut stmt = self.conn.prepare("SELECT content FROM notes WHERE id = ?1")?; + let mut stmt = self + .conn + .prepare("SELECT content FROM notes WHERE id = ?1")?; let mut rows = stmt.query_map([id], |r| r.get::<_, String>(0))?; match rows.next() { Some(r) => Ok(Some(r?)), @@ -272,7 +277,10 @@ impl Store { continue; } let snippet = snippet_around(&plain, &q); - let hit = SearchHit { note: meta, snippet }; + let hit = SearchHit { + note: meta, + snippet, + }; if in_title { title_hits.push(hit); } else { @@ -530,7 +538,10 @@ mod tests { assert_eq!(note_preview("

Hello world

"), "Hello world"); assert_eq!(note_preview(""), ""); assert_eq!(note_preview("

"), ""); - assert_eq!(note_preview(&format!("

{}

", "x".repeat(100))).len(), 60); + assert_eq!( + note_preview(&format!("

{}

", "x".repeat(100))).len(), + 60 + ); } #[test] @@ -543,8 +554,12 @@ mod tests { #[test] fn load_notes_meta_has_preview_and_counts_no_content() { let s = store(); - s.save_note(¬e("a", r#"

Title

  • x
  • "#, 1000)) - .unwrap(); + s.save_note(¬e( + "a", + r#"

    Title

  • x
  • "#, + 1000, + )) + .unwrap(); let meta = s.load_notes_meta().unwrap(); assert_eq!(meta.len(), 1); assert_eq!(meta[0].id, "a"); @@ -556,7 +571,10 @@ mod tests { fn load_note_content_returns_html_or_none() { let s = store(); s.save_note(¬e("a", "

    body

    ", 1000)).unwrap(); - assert_eq!(s.load_note_content("a").unwrap().as_deref(), Some("

    body

    ")); + assert_eq!( + s.load_note_content("a").unwrap().as_deref(), + Some("

    body

    ") + ); assert_eq!(s.load_note_content("missing").unwrap(), None); } @@ -564,9 +582,11 @@ mod tests { fn search_notes_ranks_title_first_and_snippets() { let s = store(); // body-only match - s.save_note(¬e("body", "

    Zeta

    the apple is red

    ", 10)).unwrap(); + s.save_note(¬e("body", "

    Zeta

    the apple is red

    ", 10)) + .unwrap(); // title match (higher rank) - s.save_note(¬e("title", "

    apple crumble

    ", 20)).unwrap(); + s.save_note(¬e("title", "

    apple crumble

    ", 20)) + .unwrap(); let hits = s.search_notes("apple", 50).unwrap(); assert_eq!(hits.len(), 2); assert_eq!(hits[0].note.id, "title"); // title/preview hit ranks first diff --git a/src-tauri/src/update.rs b/src-tauri/src/update.rs index e69d2b7..6f628ce 100644 --- a/src-tauri/src/update.rs +++ b/src-tauri/src/update.rs @@ -21,12 +21,18 @@ pub struct UpdateInfo { /// (missing/garbage components count as 0). pub fn is_newer(current: &str, latest: &str) -> bool { fn parts(s: &str) -> Vec { - s.trim().trim_start_matches('v').split('.') - .map(|p| p.trim().parse::().unwrap_or(0)).collect() + s.trim() + .trim_start_matches('v') + .split('.') + .map(|p| p.trim().parse::().unwrap_or(0)) + .collect() } let (c, l) = (parts(current), parts(latest)); for i in 0..c.len().max(l.len()) { - let (cv, lv) = (c.get(i).copied().unwrap_or(0), l.get(i).copied().unwrap_or(0)); + let (cv, lv) = ( + c.get(i).copied().unwrap_or(0), + l.get(i).copied().unwrap_or(0), + ); if lv != cv { return lv > cv; } @@ -45,7 +51,9 @@ pub async fn check_for_update() -> Result { .map_err(|e| e.to_string())?; let resp = client - .get(format!("https://api.github.com/repos/{REPO}/releases/latest")) + .get(format!( + "https://api.github.com/repos/{REPO}/releases/latest" + )) .header("Accept", "application/vnd.github+json") .send() .await @@ -56,13 +64,26 @@ pub async fn check_for_update() -> Result { } let body: serde_json::Value = resp.json().await.map_err(|e| e.to_string())?; - let latest = body.get("tag_name").and_then(|v| v.as_str()).unwrap_or("").to_string(); + let latest = body + .get("tag_name") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); if latest.is_empty() { return Err("no release tag found".into()); } - let url = body.get("html_url").and_then(|v| v.as_str()).unwrap_or(RELEASES_URL).to_string(); + let url = body + .get("html_url") + .and_then(|v| v.as_str()) + .unwrap_or(RELEASES_URL) + .to_string(); - Ok(UpdateInfo { update_available: is_newer(¤t, &latest), current, latest, url }) + Ok(UpdateInfo { + update_available: is_newer(¤t, &latest), + current, + latest, + url, + }) } #[cfg(test)]