breakmancer 0.9.0

Drop a breakpoint into any shell.
Documentation
#![cfg(test)]

/// Create a mapping of enum variants to expressions, for use in unit tests.
///
/// Input is an enum type along with triples of variant, variant
/// constructor, and expression. All variants of the enum must be
/// listed exactly once, and only tuple-like variants are supported.
///
/// Example:
///
/// ```
/// #[derive(Debug)]
/// enum SomeEnum {
///     A(u8),
///     C(u8, u8),
/// }
///
/// pub fn example() {
///     let by_variant = all_variant_mapping!(
///         SomeEnum => &str:
///         SomeEnum::A = (5) => "a5",
///         SomeEnum::C = (6, 7) => "c67",
///     );
///
///     println!("{:?}", by_variant); // prints [(A(5), "a5"), (C(6, 7), "c67")]
/// }
/// ```
macro_rules! all_variant_mapping {
    (
        $enum_type:path => $expr_type:ty :
        $(
            $variant:path
                = ( $( $constructor:expr ),* )
                => $value:expr,
        )*
    ) => {
        {
            // This function is never called; its only purpose is to
            // hold a match expression that will in turn ensure
            // exhaustiveness over the enum.
            fn _ensure_exhaustive(example: $enum_type) {
                match example {
                    $( $variant (..) => (), )*
                }
            }

            let kvs: Vec<($enum_type, $expr_type)> = vec![
                $( ($variant ( $( $constructor ),* ), $value) ),*
            ];

            kvs
        }
    };
}

pub(crate) use all_variant_mapping;