macro_rules! define_intermediate {
( $type_name:ident $( { $($fields:tt)* } )? ,
$get_function_name:ident, $output_type:ty, $impl_function:expr) => { ... };
( $type_name:ident $( { $($fields:tt)* } )? ,
$get_function_name:ident, cloned $output_type:ty, $impl_function:expr) => { ... };
(@inner $type_name:ident $( { $( $($(@$if_ref:tt)? &)? $field_name:ident : $field_type:ty),* } )? ,
$get_function_name:ident, $output_type:ty, $impl_function:expr; $clone_function:expr ; $($output_ref:tt)* ) => { ... };
}Expand description
Helper macro to define an intermediate computation type. This will
define the type for you along with a new method, Run impl and
a function wrapper for db.get(ComputationType::new()).
Example usage:
// Defines the `Parse` type, a `parse` function to get the current parse
// or re-parse if it is out of date, the output type String, and parse_impl
// which actually performs the parse and returns a String.
define_intermediate!(Parse, parse, String, parse_impl);
fn parse_impl(db: &mut DbHandle<impl Computation>) -> String { todo!() }
// You can also specify arguments to the type, prefixing each with `&` if it
// is to be passed by reference to `parse_impl`.
// The output type can also be prefixed with `cloned` if the getter should
// return it cloned instead of a reference
define_intermediate!(TypeCheck { &expr: Rc<Expr> }, type_check, cloned Result<Type, Error>, type_check_impl);
fn type_check_impl(expr: &Rc<Expr>, db: &mut DbHandle<impl Computation>) -> Result<Type, Error> { todo!() }