small_num

Macro small_num 

Source
macro_rules! small_num {
    (
        $( #[$meta:meta] )*
        $vis:vis enum $Name:ident : [ $($value:literal),* $(,)? ]
        $(
            where
                Self: $FirstTrait:ident $( + $TailTraits:ident )*
        )?
        ;
    ) => { ... };
    (
        $( #[$meta:meta] )*
        $vis:vis enum $Name:ident : $start:literal..$end:literal
        $(
            where
                Self: $FirstTrait:ident $( + $TailTraits:ident )*
        )?
        ;
    ) => { ... };
    (
        $( #[$meta:meta] )*
        $vis:vis enum $Name:ident : $start:literal..=$end:literal
        $(
            where
                Self: $FirstTrait:ident $( + $TailTrait:ident )*
        )?
        ;
    ) => { ... };
    (
        $( #[$meta:meta] )*
        $vis:vis enum $Name:ident : ..$end:literal
        $(
            where
                Self: $FirstTrait:ident $( + $TailTraits:ident )*
        )?
        ;
    ) => { ... };
    (
        $( #[$meta:meta] )*
        $vis:vis enum $Name:ident : ..=$end:literal
        $(
            where
                Self: $FirstTrait:ident $( + $TailTraits:ident )*
        )?
        ;
    ) => { ... };
    (
        $( #[$meta:meta] )*
        $vis:vis enum $Name:ident : $( $start:literal )? ..
        $(
            where
                Self: $FirstTrait:ident $( + $TailTraits:ident )*
        )?
        ;
    ) => { ... };
    (
        @derive(Serialize)
        $Name:ident
    ) => { ... };
    (
        @derive(Deserialize)
        $Name:ident
    ) => { ... };
    (
        @derive(Debug)
        $Name:ident
    ) => { ... };
    (
        @derive( $Trait:ident )
        $Name:ident
    ) => { ... };
    (
        @derive( $( $Trait:ident ),* $(,)? )
        $Name:ident
    ) => { ... };
}
Expand description

Macro used to create small numbers. It comes in two forms: as a range and a list of valid values.

§List form

It creates enum with given list of values.

small_num! {
    pub enum ListNum: [<list of values>];
}

§Range form

It creates enum with all numbers from given range.

small_num! {
    pub enum RangeNum: <START>..<END>;
}

§small-num custom traits derivation

small_num! {
    pub enum Num: [10, 9, 8, 7];
    where
        Self: <TRAIT_1> + <TRAIT_2>;
}