use std::sync::Arc;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Key(pub [u8; 32]);
pub trait Store: std::fmt::Debug + Send + Sync {
fn get(&self, key: &Key) -> Option<Vec<u8>>;
fn put(&self, key: &Key, value: &[u8]);
}
#[derive(Clone, Debug)]
pub struct Memo {
pub store: Arc<dyn Store>,
pub build: String,
}
impl Memo {
pub fn new(store: Arc<dyn Store>, build: impl Into<String>) -> Result<Self, String> {
let build = build.into();
if build.is_empty() {
return Err(
"a memo store needs the build identity (the primase revision) its entries are valid for"
.into(),
);
}
Ok(Self { store, build })
}
}
impl crate::Resource for Memo {
const NAME: &'static str = "core.pass_memo";
}