macro_rules! impl_storage {
($typ:ty, $( $field:ident : $computation_type:ty ),* $(, )? ) => { ... };
}Expand description
Implements Storage for a struct type. This enables the given struct type S to be used
as a generic on Db<S> to store all computations cached by the program.
This will also create forwarding impls for StorageFor<ComputationType> for each field,
computation type pair used.
Example usage:
use inc_complete::{ impl_storage, define_input, define_intermediate };
use inc_complete::storage::{ SingletonStorage, HashMapStorage };
#[derive(Default)]
struct MyStorage {
foos: SingletonStorage<Foo>,
bars: HashMapStorage<Bar>,
}
impl_storage!(MyStorage,
foos: Foo,
bars: Bar,
);
// Each input & intermediate computation should implement Clone
#[derive(Clone)]
struct Foo;
define_input!(0, Foo -> usize, MyStorage);
// HashMapStorage requires Eq and Hash
#[derive(Clone, PartialEq, Eq, Hash)]
struct Bar(std::rc::Rc<String>);
define_intermediate!(1, Bar -> usize, MyStorage, |bar, db| {
bar.0.len() + *db.get(Foo)
});Note that using this macro requires each computation type to implement Clone.