ConstDefault

Macro ConstDefault 

Source
macro_rules! ConstDefault {
    (
        $(#[$attr:meta])+
        $vis:vis enum $enum_name:ident {
            $($body:tt)*
        }
    ) => { ... };
    (
        $(#[$attr:meta])+
        $vis:vis struct $struct_name:ident $($rest:tt)*
    ) => { ... };
    (
        enum $enum_name:ident {
            #[custom(default)]
            $(#[$other_variant_attr:meta])*
            $variant_name:ident $(= $discriminant:expr)?,
            $( $rest_of_body:tt )*
        }
    ) => { ... };
    (
        enum $enum_name:ident {
            #[$attr_that_is_not_default:meta]
            $( $rest_of_body:tt )*
        }
    ) => { ... };
    (
        enum $enum_name:ident {
            $variant_name:ident $(= $discriminant:expr)?,
            $( $rest_of_body:tt )*
        }
    ) => { ... };
    (
        enum $enum_name:ident {
            $variant_name:ident ( $( $field_tokens:tt )* ),
            $( $rest_of_body:tt )*
        }
    ) => { ... };
    (
        enum $enum_name:ident {
            $variant_name:ident { $( $field_tokens:tt )* },
            $( $rest_of_body:tt )*
        }
    ) => { ... };
    (
        $(#[$struct_attr:meta])*
        $vis:vis struct $struct_name:ident {
            $(
                $(#[$field_attr:meta])*
                $field_vis:vis $field_name:ident : $field_type:ty,
            )*
        }
    ) => { ... };
    (
        $(#[$struct_attr:meta])*
        $vis:vis struct $struct_name:ident(
            $(
                $(#[$field_attr:meta])*
                $field_vis:vis $field_type:ty
            ),* $(,)?
        );
    ) => { ... };
}
Expand description

Macro for use with [macro_rules_attribute::derive] to derive a const fn default() in addition to impl Default.

Generics are not supported.

When using this macro on an enum, the default variant must be marked with #[custom(default)], rather than #[default] as the built-in derive macro does. This is a limitation of [macro_rules_attribute::derive].