harmos_domain/operations/common/
key.rs1pub const MAX_CACHE_KEY_BYTES: usize = 256;
25
26#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
33pub struct CacheKey(Box<[u8]>);
34
35#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
38pub enum CacheKeyError {
39 #[error("cache key has {actual} bytes; maximum is {maximum}")]
40 TooLarge { actual: usize, maximum: usize },
41}
42
43impl CacheKey {
48 pub fn new(bytes: impl Into<Box<[u8]>>) -> Result<Self, CacheKeyError> {
49 let bytes = bytes.into();
50 if bytes.len() > MAX_CACHE_KEY_BYTES {
51 return Err(CacheKeyError::TooLarge { actual: bytes.len(), maximum: MAX_CACHE_KEY_BYTES });
52 }
53
54 Ok(Self(bytes))
55 }
56
57 pub fn as_bytes(&self) -> &[u8] {
58 &self.0
59 }
60}
61
62