You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a struct with non-optional values but with defaults. Currently I define it like this:
#[derive(Args,Clone)]#[cfg_attr(test, derive(PartialEq,Debug))]pub(crate)structServerSettings{/// Server name that will be visible to other players.#[clap(short, long, default_value_t = ServerSettings::default().server_name)]pub(crate)server_name:String,/// IP address to bind.#[clap(short, long, default_value_t = ServerSettings::default().ip)]pub(crate)ip:String,/// Port to use.#[clap(short, long, default_value_t = ServerSettings::default().port)]pub(crate)port:u16,/// Game mode.#[clap(short, long, default_value_t = ServerSettings::default().game_mode)]pub(crate)game_mode:GameMode,/// Game map.#[clap(short, long, default_value_t = ServerSettings::default().map)]pub(crate)map:Map,/// Choose heroes randomly.#[clap(short, long)]pub(crate)random_heroes:bool,}
Because default_value_t uses Default::default for the underlying type, not from the struct. It's very unergonomic and error-prone.
Describe the solution you'd like
It would be nice to have an attribute to use default value from the struct's Default trait.
Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Please complete the following tasks
Clap Version
3.1.8
Describe your use case
I have a struct with non-optional values but with defaults. Currently I define it like this:
Because
default_value_t
usesDefault::default
for the underlying type, not from the struct. It's very unergonomic and error-prone.Describe the solution you'd like
It would be nice to have an attribute to use default value from the struct's
Default
trait.Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: