Skip to main content

agentics_storage/
intent.rs

1use crate::{Result, StorageError};
2
3/// Storage write/read purpose with an explicit byte cap.
4#[derive(Debug, Clone, Copy)]
5pub struct StorageWriteIntent {
6    label: &'static str,
7    max_bytes: u64,
8}
9
10impl StorageWriteIntent {
11    /// Create a write intent with a caller-owned byte limit.
12    pub const fn new(label: &'static str, max_bytes: u64) -> Self {
13        Self { label, max_bytes }
14    }
15
16    /// User-facing purpose label.
17    pub const fn label(self) -> &'static str {
18        self.label
19    }
20
21    /// Maximum bytes allowed for this object.
22    pub const fn max_bytes(self) -> u64 {
23        self.max_bytes
24    }
25
26    /// Verify a byte length against this intent.
27    pub fn ensure_len(self, actual: u64) -> Result<()> {
28        if actual > self.max_bytes {
29            return Err(StorageError::ObjectTooLarge {
30                label: self.label,
31                actual,
32                limit: self.max_bytes,
33            });
34        }
35        Ok(())
36    }
37}