Skip to main content

s_no_extra_traits2

Macro s_no_extra_traits2 

Source
macro_rules! s_no_extra_traits2 {
    ($(
        $(#$attr:tt)*
        $pub:vis $t:ident $i:ident { $($field:tt)* }
    )*) => { ... };
    (it: $(#$attr:tt)* $pub:vis union $i:ident { $($field:tt)* }) => { ... };
    (it: $(#$attr:tt)* $pub:vis struct $i:ident { $($field:tt)* }) => { ... };
}
Expand description

Like [s_no_extra_traits], but (1) generates a Default impl for every struct in the block, and (2) adds a private field to replicate the effects of the built-in non_exhaustive attribute while rust-lang/rust#132699 gets sorted out.

Unions are emitted just like s_no_extra_traits! does, with no Default. A struct field of union type supplies its own default via #[custom_default(...)].

To opt out of having the private field added, annotate the struct with an exhaustive attribute, as in:

ⓘ
s_no_extra_traits2! {
    #[exhaustive]
    struct Something {
        ...
    }
}