Macro define_intermediate

Source
macro_rules! define_intermediate {
    ( $id:tt, $type_name:ident -> $output_type:ty, $( $storage_type:ty )|+, $run_function:expr) => { ... };
}
Expand description

Helper macro to define an intermediate computation type. This will implement OutputType, ComputationId, and Run.

This macro supports multiple Storage types used, separated by |, in case your program uses multiple databases with differing storage types.

Signature: define_intermediate!(computation_id, ComputationType -> OutputType, StorageType ( | MoreStorageTypes)*, run_function)

Example usage:

#[derive(Clone)]
struct Double;

// Define `Double` as a computation with id 1 and the given run function which returns an `i32`
// to be used with a `Db<MyStorageType>` or `DbHandle<MyStorageType>`.
// The type annotations on the closure are unnecessary.
// We also may provide an existing function instead of a closure.
define_intermediate!(1, Double -> i32, MyStorageType, |_: &Double, db: &mut DbHandle<MyStorageType>| {
    *db.get(MyInput) * 2
});