Macro hotdrink_rs::component[][src]

macro_rules! component {
    (@value_or_default: $t:ty ) => { ... };
    (@value_or_default: $t:ty = $value:expr) => { ... };
    (
        // Match a component, its name, and constraints.
        component $component_name:ident {
            // Match variables, their types, and default values.
            let $($i:ident: $val_ty:ty $( = $e:expr )? ),*;
            $(
                // Match a constraint, its name, and methods.
                constraint $constraint_name:ident {
                    // Match a precondition of the constraint.
                    $( precondition $precondition:expr; )?
                    // Match a postcondition of the constraint.
                    $( postcondition $postcondition:expr; )?
                    $(
                        // Match a method, its inputs, outputs and body.
                        $method_name:ident
                            ($($inp:ident: $inp_ty:ty),*)
                            $(-> [$($out:ident),*])?
                            = $m_expr:expr;
                    )*
                }
            )*
        }
    ) => { ... };
}

A macro for specifying components.

This can be used to construct constraint systems declaratively by combining the desired components in a ConstraintSystem.

Examples

let component: Component<i32> = component! {
    component SumAndProduct {
        let a: i32 = 0, b: i32 = 0, c: i32 = 0, d: i32 = 0;
        constraint Sum {
            sum1(a: &i32, b: &i32) -> [c] = ret![*a + *b];
            sum2(a: &i32, c: &i32) -> [b] = ret![*c - *a];
            sum3(b: &i32, c: &i32) -> [a] = ret![*c - *b];
        }
        constraint Product {
            product1(a: &i32, b: &i32) -> [d] = ret![*a * *b];
            product2(a: &i32, d: &i32) -> [b] = ret![*d / *a];
            product3(b: &i32, d: &i32) -> [a] = ret![*d / *b];
        }
    }
};