Inline Default
A macro for implementing Default
within a struct definition.
This is useful when specifying the default values within the struct
definition is cleaner than separating them,
for example structs with a large number fields,
or when many structs are constructed.
For example,
use inline_default;
inline_default!
expands to
Supports:
- Visibility specifiers
- Use Default if not specified
- Attributes (including derives) on both the struct and the fields
- Doc comments on both the struct and the fields
- Multiple struct definitions within each macro
- Lifetimes and generics, with major caveats
Due to the complexity in parsing trait bounds,
only a single trait bound without generics is accepted.
where
clauses are not supported.
Specifying lifetimes are accepted, but not the 'outlives' syntax 'a: 'b
.
For example, the following is accepted,
use inline_default;
inline_default!
but the following are not:
use inline_default;
// NOT VALID - too many trait bounds on T
inline_default!
// NOT VALID - Traits bounds cannot be generic
inline_default!
// NOT VALID - outlives syntax is not supported
inline_default!
Proc Macro?
Making a proc macro would be fuller feature-wise, but I can't be bothered.