I noticed that there is no simple macro to define structs with default values that emulates the following pattern:
default_struct! Config {
version: (u64, u64, u64) = (0, 1, 0),
// Automatically assigned
authors: Vec<String>,
}
Thus I created my own library crates.io/crates/short_default which comes close:
default! {
struct Config {
version: (u64, u64, u64) = (0, 1, 0),
// Automatically assigned
authors: Vec<String>,
}
}
I suppose with the current state of macros in Rust it is not possible to create a macro which "replaces" the struct keyword. Please let me know what you think. Would you use this?
I am aware of the existence of the derivative crate which solves similar problems but find the ergonomics of having to resort to field attributes cumbersome (specifically for default values, not necessarily others such as formatting).