casserole/
ser.rs

1use crate::store::Store;
2
3/// The Casserole trait provides reduction and restoration of values to compact
4/// form where sub-values are stored in a Store, which can be a content-addressable
5/// database.
6pub trait Casserole<S>: Sized
7where
8    S: Store,
9{
10    /// The target type. Usually contains all the details of the original types
11    /// except some sub-values which are stored in a DB and are only accessible
12    /// via a key.
13    type Target: serde::Serialize;
14
15    /// Serialization that handles folding. The returned value is a folded
16    /// representation of the given type, where the folded portions are
17    /// saved in a store.
18    ///
19    /// This function is expected to use the store to perform puts.
20    fn casserole(&self, store: &mut S) -> Result<Self::Target, S::Error>;
21
22    /// The reverse of `casserole`, returning the original object. This
23    /// function is expected to use the given store to preform gets.
24    fn decasserole(target: &Self::Target, store: &mut S) -> Result<Self, S::Error>;
25}