mirror of
https://github.com/perstarkse/minne.git
synced 2026-05-28 02:19:34 +02:00
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
This commit is contained in:
@@ -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<PathBuf> {
|
||||
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)
|
||||
|
||||
@@ -60,6 +60,7 @@ where
|
||||
}
|
||||
|
||||
impl Conversation {
|
||||
#[must_use]
|
||||
pub fn new(user_id: String, title: String) -> Self {
|
||||
let now = Utc::now();
|
||||
Self {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -32,6 +32,7 @@ impl KnowledgeEntityEmbedding {
|
||||
}
|
||||
|
||||
/// Create a new knowledge entity embedding
|
||||
#[must_use]
|
||||
pub fn new(entity_id: &str, embedding: Vec<f32>, user_id: String) -> Self {
|
||||
let now = Utc::now();
|
||||
Self {
|
||||
|
||||
@@ -21,6 +21,7 @@ pub struct KnowledgeRelationship {
|
||||
}
|
||||
|
||||
impl KnowledgeRelationship {
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
in_: String,
|
||||
out: String,
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<f32>, user_id: String) -> Self {
|
||||
let now = Utc::now();
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ stored_object!(TextContent, "text_content", {
|
||||
});
|
||||
|
||||
impl TextContent {
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
text: String,
|
||||
context: Option<String>,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<String> {
|
||||
match &self.inner {
|
||||
EmbeddingInner::FastEmbed { model_name, .. } => Some(model_name.to_string()),
|
||||
|
||||
Reference in New Issue
Block a user