use crate::{Result, StorageError};
#[derive(Debug, Clone, Copy)]
pub struct StorageWriteIntent {
label: &'static str,
max_bytes: u64,
}
impl StorageWriteIntent {
pub const fn new(label: &'static str, max_bytes: u64) -> Self {
Self { label, max_bytes }
}
pub const fn label(self) -> &'static str {
self.label
}
pub const fn max_bytes(self) -> u64 {
self.max_bytes
}
pub fn ensure_len(self, actual: u64) -> Result<()> {
if actual > self.max_bytes {
return Err(StorageError::ObjectTooLarge {
label: self.label,
actual,
limit: self.max_bytes,
});
}
Ok(())
}
}