ctif_specialize

Macro ctif_specialize 

Source
macro_rules! ctif_specialize {
    (
        $( #[$meta_links:meta] )*
        trait_name = $trait:ident,
        conditions = [$($cond:path),+]
    ) => { ... };
}
Expand description

Macro for specializing CTIf.

If receiving associated types are constrained, the generic CTIf is not usable any more because there is no syntax carrying over these constraints accross the IF test. Solving this requires building a new trait similar to CTIf with constraints which are specific to your use case. These constraints will be applied to CTIf::Path.

This macro helps in building that specialization. It creates a specialized trait and implements it for IfCheck, the latter can be re-used accross specializations. Implementers only need to provide a new name for the trait and the required constraints. Provided outer attributes are applied to the newly created trait as well.

Using this specialized trait is analogue to using CTIf and IfCheck.

§Example

ctif_specialize {
    /// Optional doc-attribute explaining things about the special IF test.
    trait_name = "MySpecialIf",
    conditions = [Add<u32>, Mul<u32>]
}

That macro call will expand to the following code.

/// Optional doc-attribute explaining things about the special IF test.
pub trait MySpecialIf<Condition, OptionTrue, OptionFalse> {
    type Result: CTBool;
    type Path: Add<u32> + Mul<u32>;
}