From c71c576c2978f0e4ff0e2039ee750b53182f184b Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 17 Mar 2026 21:25:22 +0300 Subject: [PATCH] core/types: make results explicit for `cleanup()` Signed-off-by: NotAShelf Change-Id: I5795e5c6eb10d9a869d3cc88f2fdbb926a6a6964 --- src/core/types.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/core/types.rs b/src/core/types.rs index 9c96484..5c3e19e 100644 --- a/src/core/types.rs +++ b/src/core/types.rs @@ -4,9 +4,11 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] +#[must_use] pub struct ContentHash(pub String); impl ContentHash { + /// Creates a new content hash. pub fn new(hash: impl Into) -> Self { Self(hash.into()) } @@ -19,6 +21,7 @@ impl AsRef for ContentHash { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] +#[must_use] pub struct JobId(pub uuid::Uuid); impl JobId { @@ -34,6 +37,7 @@ impl Default for JobId { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] +#[must_use] pub struct RunId(pub uuid::Uuid); impl RunId { @@ -50,6 +54,7 @@ impl Default for RunId { #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] +#[must_use] pub enum JobStatus { Discovered, Fetching, @@ -60,6 +65,7 @@ pub enum JobStatus { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[must_use] pub struct SourceProvenance { pub source_id: String, pub entity_type: EntityType, @@ -69,6 +75,7 @@ pub struct SourceProvenance { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] +#[must_use] pub enum EntityType { Repository, Wiki, @@ -89,6 +96,7 @@ pub struct Artifact { } impl Artifact { + #[must_use] pub const fn new( content_hash: ContentHash, size_bytes: u64, @@ -103,18 +111,27 @@ impl Artifact { } } + /// Returns the path to the temporary file. + #[must_use] pub fn temp_path(&self) -> &std::path::Path { &self.temp_path } - /// Explicitly clean up the temporary file. - /// This should be called after all sinks have processed the artifact. - pub async fn cleanup(&self) { - let _ = tokio::fs::remove_file(&self.temp_path).await; + /// Explicitly clean up the temporary file. This should be called after all + /// sinks have processed the artifact. + /// + /// # Errors + /// + /// Returns an error if the file cannot be removed (e.g., permissions, + /// file not found, or IO errors). + pub async fn cleanup(&self) -> anyhow::Result<()> { + tokio::fs::remove_file(&self.temp_path).await?; + Ok(()) } } #[derive(Debug, Clone, Serialize, Deserialize)] +#[must_use] pub struct SinkJobState { pub status: JobStatus, pub receipt: Option, @@ -122,6 +139,7 @@ pub struct SinkJobState { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[must_use] pub struct StorageReceipt { pub sink_id: String, pub uri: String, @@ -129,6 +147,7 @@ pub struct StorageReceipt { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[must_use] pub struct ManifestEntry { pub hash: ContentHash, pub size: u64, @@ -149,6 +168,7 @@ pub struct Job { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[must_use] pub struct Manifest { pub run_id: RunId, pub created_at: DateTime,