impl_storage

Macro impl_storage 

Source
macro_rules! impl_storage {
    ($typ:ty, $( $field:ident : $computation_type:ty, )* $(@accumulators { $($acc_field:ident : $acc_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 };
use inc_complete::accumulate::{ Accumulator, Accumulate };

#[derive(Default)]
struct MyStorage {
    foos: SingletonStorage<Foo>,
    bars: HashMapStorage<Bar>,
    logs: Accumulator<Log>,
}

impl_storage!(MyStorage,
    foos: Foo,
    bars: Bar,
    @accumulators {
        logs: Log,
    }
);

// Each input & intermediate computation should implement Debug & Clone
#[derive(Debug, Clone)]
struct Foo;
define_input!(0, Foo -> usize, MyStorage);

// HashMapStorage requires Eq and Hash
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct Bar(std::rc::Rc<String>);
define_intermediate!(1, Bar -> usize, MyStorage, |bar, db| {
    bar.0.len() + db.get(Foo)
});

// Accumulated values need to derive Eq, Clone, and Debug
#[derive(Debug, PartialEq, Eq, Clone)]
struct Log;

Note that using this macro requires each computation type to implement Clone.