From 993dc4a52546d28c5b1b1ee73298eb9a198f677c Mon Sep 17 00:00:00 2001 From: Breadway Date: Thu, 6 Aug 2026 08:52:18 +0800 Subject: [PATCH] Fix cargo clippy warnings across the workspace - Derive Default for Config instead of manually mirroring each sub-config's Default impl - Use std::io::Error::other instead of Error::new(ErrorKind::Other, ..) - Drop the unused mut on the store lock in full_reindex - Remove Store::dim, a field that was set once and never read - Use char_indices().enumerate() instead of a hand-rolled loop counter in split_by_chars, and is_multiple_of() for the chunk boundary check - Use strip_prefix instead of manual slicing in expand_home (cherry picked from commit b740af38e17d04bd83db93bbb0585ed5744a436e) --- breadmill/src/chunk.rs | 6 ++---- breadmill/src/indexer.rs | 6 +++--- breadmill/src/store.rs | 3 +-- breadsearch-shared/src/lib.rs | 15 ++------------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/breadmill/src/chunk.rs b/breadmill/src/chunk.rs index dcddca8..7468f89 100644 --- a/breadmill/src/chunk.rs +++ b/breadmill/src/chunk.rs @@ -81,10 +81,9 @@ fn split_by_chars(chunk: Chunk, max_chars: usize) -> Vec { let text = &chunk.text; let mut result = Vec::new(); let mut seg_start = 0usize; - let mut count = 0usize; - for (byte_idx, _) in text.char_indices() { - if count > 0 && count % max_chars == 0 { + for (count, (byte_idx, _)) in text.char_indices().enumerate() { + if count > 0 && count.is_multiple_of(max_chars) { result.push(Chunk { text: text[seg_start..byte_idx].to_string(), start: chunk.start + seg_start, @@ -92,7 +91,6 @@ fn split_by_chars(chunk: Chunk, max_chars: usize) -> Vec { }); seg_start = byte_idx; } - count += 1; } if seg_start < text.len() { result.push(Chunk { diff --git a/breadmill/src/indexer.rs b/breadmill/src/indexer.rs index 539b58c..67c7694 100644 --- a/breadmill/src/indexer.rs +++ b/breadmill/src/indexer.rs @@ -64,7 +64,7 @@ impl Indexer { pub fn full_reindex(&self) { eprintln!("breadmill: full reindex triggered"); { - let mut store = self.state.store.lock_recover(); + let store = self.state.store.lock_recover(); // Clear all state let _ = store.conn.execute_batch("DELETE FROM chunks; DELETE FROM files;"); let _ = store.index.reserve(4096); @@ -416,9 +416,9 @@ fn sha256_str(bytes: &[u8]) -> String { } pub fn expand_home(path: &str) -> PathBuf { - if path.starts_with("~/") { + if let Some(rest) = path.strip_prefix("~/") { let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".into()); - PathBuf::from(home).join(&path[2..]) + PathBuf::from(home).join(rest) } else { PathBuf::from(path) } diff --git a/breadmill/src/store.rs b/breadmill/src/store.rs index ed1392a..106e4c5 100644 --- a/breadmill/src/store.rs +++ b/breadmill/src/store.rs @@ -6,7 +6,6 @@ use usearch::{Index, IndexOptions, MetricKind, ScalarKind, new_index}; pub struct Store { pub conn: Connection, pub index: Index, - pub dim: usize, } // usearch::Index wraps a raw C++ pointer; access is serialized by the Mutex. @@ -87,7 +86,7 @@ impl Store { index.reserve(4096).map_err(|e| e.to_string())?; } - Ok(Self { conn, index, dim }) + Ok(Self { conn, index }) } // ---- file state --------------------------------------------------------- diff --git a/breadsearch-shared/src/lib.rs b/breadsearch-shared/src/lib.rs index fdea6f5..5ed69c4 100644 --- a/breadsearch-shared/src/lib.rs +++ b/breadsearch-shared/src/lib.rs @@ -43,7 +43,7 @@ pub fn socket_path() -> PathBuf { // ---- Config ----------------------------------------------------------------- -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct Config { #[serde(default)] pub index: IndexConfig, @@ -157,16 +157,6 @@ impl Default for ModelConfig { } } -impl Default for Config { - fn default() -> Self { - Self { - index: IndexConfig::default(), - search: SearchConfig::default(), - model: ModelConfig::default(), - power: PowerConfig::default(), - } - } -} #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PowerConfig { @@ -255,8 +245,7 @@ pub struct StatusInfo { pub fn send_request(req: &Request) -> std::io::Result { let mut stream = UnixStream::connect(socket_path())?; - let mut line = serde_json::to_string(req) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?; + let mut line = serde_json::to_string(req).map_err(std::io::Error::other)?; line.push('\n'); stream.write_all(line.as_bytes())?; stream.flush()?;