From 45d13230a667efd22417e3b27b7118629bc6a5e7 Mon Sep 17 00:00:00 2001 From: Per Stark Date: Wed, 27 May 2026 14:23:56 +0200 Subject: [PATCH] chore: add must_use to 27 non-Result public functions - constructors: KnowledgeEntity, TextChunk, Scratchpad, IngestionTask, Conversation, KnowledgeRelationship, Message, TextContent, KnowledgeEntityEmbedding, TextChunkEmbedding - accessors: Theme::as_str, Theme::initial_theme, TaskState::as_str, TaskState::display_label, StorageManager::backend_kind, StorageManager::local_base_path, EmbeddingProvider::backend_label, EmbeddingProvider::dimension, EmbeddingProvider::model_code - queries: TaskState::is_terminal, IngestionTask::can_retry, KnowledgeEntityType::variants, StorageManager::resolve_local_path, resolve_base_dir, IngestionTask::lease_duration - helpers: Message::format_history - builders: StorageManager::with_backend --- common/src/storage/store.rs | 5 +++++ common/src/storage/types/conversation.rs | 1 + common/src/storage/types/ingestion_task.rs | 6 ++++++ common/src/storage/types/knowledge_entity.rs | 2 ++ common/src/storage/types/knowledge_entity_embedding.rs | 1 + common/src/storage/types/knowledge_relationship.rs | 1 + common/src/storage/types/message.rs | 2 ++ common/src/storage/types/scratchpad.rs | 1 + common/src/storage/types/text_chunk.rs | 1 + common/src/storage/types/text_chunk_embedding.rs | 1 + common/src/storage/types/text_content.rs | 1 + common/src/storage/types/user.rs | 2 ++ common/src/utils/embedding.rs | 3 +++ 13 files changed, 27 insertions(+) diff --git a/common/src/storage/store.rs b/common/src/storage/store.rs index 1c080f3..9a50204 100644 --- a/common/src/storage/store.rs +++ b/common/src/storage/store.rs @@ -46,6 +46,7 @@ impl StorageManager { /// /// This method is useful for testing scenarios where you want to inject /// a specific storage backend. + #[must_use] pub fn with_backend(store: DynStorage, backend_kind: StorageKind) -> Self { Self { store, @@ -55,11 +56,13 @@ impl StorageManager { } /// Get the storage backend kind. + #[must_use] pub fn backend_kind(&self) -> &StorageKind { &self.backend_kind } /// Access the resolved local base directory when using the local backend. + #[must_use] pub fn local_base_path(&self) -> Option<&Path> { self.local_base.as_deref() } @@ -68,6 +71,7 @@ impl StorageManager { /// /// Returns `None` when the backend is not local or when the provided location includes /// unsupported components (absolute paths or parent traversals). + #[must_use] pub fn resolve_local_path(&self, location: &str) -> Option { let base = self.local_base_path()?; let relative = Path::new(location); @@ -544,6 +548,7 @@ pub mod testing { /// Resolve the absolute base directory used for local storage from config. /// /// If `data_dir` is relative, it is resolved against the current working directory. +#[must_use] pub fn resolve_base_dir(cfg: &AppConfig) -> PathBuf { if cfg.data_dir.starts_with('/') { PathBuf::from(&cfg.data_dir) diff --git a/common/src/storage/types/conversation.rs b/common/src/storage/types/conversation.rs index c0b3bb1..6484203 100644 --- a/common/src/storage/types/conversation.rs +++ b/common/src/storage/types/conversation.rs @@ -60,6 +60,7 @@ where } impl Conversation { + #[must_use] pub fn new(user_id: String, title: String) -> Self { let now = Utc::now(); Self { diff --git a/common/src/storage/types/ingestion_task.rs b/common/src/storage/types/ingestion_task.rs index f227653..d332a9f 100644 --- a/common/src/storage/types/ingestion_task.rs +++ b/common/src/storage/types/ingestion_task.rs @@ -33,6 +33,7 @@ pub enum TaskState { } impl TaskState { + #[must_use] pub fn as_str(&self) -> &'static str { match self { TaskState::Pending => "Pending", @@ -45,6 +46,7 @@ impl TaskState { } } + #[must_use] pub fn is_terminal(&self) -> bool { matches!( self, @@ -52,6 +54,7 @@ impl TaskState { ) } + #[must_use] pub fn display_label(&self) -> &'static str { match self { TaskState::Pending => "Pending", @@ -170,6 +173,7 @@ stored_object!(IngestionTask, "ingestion_task", { }); impl IngestionTask { + #[must_use] pub fn new(content: IngestionPayload, user_id: String) -> Self { let now = chrono::Utc::now(); @@ -193,10 +197,12 @@ impl IngestionTask { } } + #[must_use] pub fn can_retry(&self) -> bool { self.attempts < self.max_attempts } + #[must_use] pub fn lease_duration(&self) -> Duration { Duration::from_secs(u64::try_from(self.lease_duration_secs.max(0)).unwrap_or(0)) } diff --git a/common/src/storage/types/knowledge_entity.rs b/common/src/storage/types/knowledge_entity.rs index 7c4e860..af3f8c7 100644 --- a/common/src/storage/types/knowledge_entity.rs +++ b/common/src/storage/types/knowledge_entity.rs @@ -34,6 +34,7 @@ pub enum KnowledgeEntityType { // Add more types as needed } impl KnowledgeEntityType { + #[must_use] pub fn variants() -> &'static [&'static str] { &["Idea", "Project", "Document", "Page", "TextSnippet"] } @@ -101,6 +102,7 @@ pub struct KnowledgeEntityVectorResult { } impl KnowledgeEntity { + #[must_use] pub fn new( source_id: String, name: String, diff --git a/common/src/storage/types/knowledge_entity_embedding.rs b/common/src/storage/types/knowledge_entity_embedding.rs index 5c16d3b..4fa994d 100644 --- a/common/src/storage/types/knowledge_entity_embedding.rs +++ b/common/src/storage/types/knowledge_entity_embedding.rs @@ -32,6 +32,7 @@ impl KnowledgeEntityEmbedding { } /// Create a new knowledge entity embedding + #[must_use] pub fn new(entity_id: &str, embedding: Vec, user_id: String) -> Self { let now = Utc::now(); Self { diff --git a/common/src/storage/types/knowledge_relationship.rs b/common/src/storage/types/knowledge_relationship.rs index 313d9f6..f649fd6 100644 --- a/common/src/storage/types/knowledge_relationship.rs +++ b/common/src/storage/types/knowledge_relationship.rs @@ -21,6 +21,7 @@ pub struct KnowledgeRelationship { } impl KnowledgeRelationship { + #[must_use] pub fn new( in_: String, out: String, diff --git a/common/src/storage/types/message.rs b/common/src/storage/types/message.rs index e3e338c..f478f5a 100644 --- a/common/src/storage/types/message.rs +++ b/common/src/storage/types/message.rs @@ -21,6 +21,7 @@ stored_object!(Message, "message", { }); impl Message { + #[must_use] pub fn new( conversation_id: String, role: MessageRole, @@ -57,6 +58,7 @@ impl fmt::Display for Message { } // helper function to format a vector of messages +#[must_use] pub fn format_history(history: &[Message]) -> String { let mut out = String::new(); for (i, msg) in history.iter().enumerate() { diff --git a/common/src/storage/types/scratchpad.rs b/common/src/storage/types/scratchpad.rs index 9d966f0..5de11b9 100644 --- a/common/src/storage/types/scratchpad.rs +++ b/common/src/storage/types/scratchpad.rs @@ -28,6 +28,7 @@ stored_object!(Scratchpad, "scratchpad", { }); impl Scratchpad { + #[must_use] pub fn new(user_id: String, title: String) -> Self { let now = ChronoUtc::now(); Self { diff --git a/common/src/storage/types/text_chunk.rs b/common/src/storage/types/text_chunk.rs index 2868dc5..0e60d5d 100644 --- a/common/src/storage/types/text_chunk.rs +++ b/common/src/storage/types/text_chunk.rs @@ -28,6 +28,7 @@ pub struct TextChunkSearchResult { } impl TextChunk { + #[must_use] pub fn new(source_id: String, chunk: String, user_id: String) -> Self { let now = Utc::now(); Self { diff --git a/common/src/storage/types/text_chunk_embedding.rs b/common/src/storage/types/text_chunk_embedding.rs index 8fdbb81..35545e0 100644 --- a/common/src/storage/types/text_chunk_embedding.rs +++ b/common/src/storage/types/text_chunk_embedding.rs @@ -41,6 +41,7 @@ impl TextChunkEmbedding { /// /// `chunk_id` is the **key** part of the text_chunk id (e.g. the UUID), /// not "text_chunk:uuid". + #[must_use] pub fn new(chunk_id: &str, source_id: String, embedding: Vec, user_id: String) -> Self { let now = Utc::now(); diff --git a/common/src/storage/types/text_content.rs b/common/src/storage/types/text_content.rs index bc75e9a..25c8aef 100644 --- a/common/src/storage/types/text_content.rs +++ b/common/src/storage/types/text_content.rs @@ -69,6 +69,7 @@ stored_object!(TextContent, "text_content", { }); impl TextContent { + #[must_use] pub fn new( text: String, context: Option, diff --git a/common/src/storage/types/user.rs b/common/src/storage/types/user.rs index 1f8f3bb..475773b 100644 --- a/common/src/storage/types/user.rs +++ b/common/src/storage/types/user.rs @@ -55,6 +55,7 @@ impl FromStr for Theme { } impl Theme { + #[must_use] pub fn as_str(&self) -> &'static str { match self { Self::Light => "light", @@ -67,6 +68,7 @@ impl Theme { /// Returns the theme that should be initially applied. /// For "system", defaults to "light". + #[must_use] pub fn initial_theme(&self) -> &'static str { match self { Self::System => "light", diff --git a/common/src/utils/embedding.rs b/common/src/utils/embedding.rs index 143800f..c097925 100644 --- a/common/src/utils/embedding.rs +++ b/common/src/utils/embedding.rs @@ -78,6 +78,7 @@ enum EmbeddingInner { } impl EmbeddingProvider { + #[must_use] pub fn backend_label(&self) -> &'static str { match self.inner { EmbeddingInner::Hashed { .. } => "hashed", @@ -86,6 +87,7 @@ impl EmbeddingProvider { } } + #[must_use] pub fn dimension(&self) -> usize { match &self.inner { EmbeddingInner::Hashed { dimension } | EmbeddingInner::FastEmbed { dimension, .. } => { @@ -95,6 +97,7 @@ impl EmbeddingProvider { } } + #[must_use] pub fn model_code(&self) -> Option { match &self.inner { EmbeddingInner::FastEmbed { model_name, .. } => Some(model_name.to_string()),