Skip to content
Discussion options

You must be logged in to vote

Currently, this is unsupported. You can possibly work around it by having functions for each shared default and doing #[arg(default_value_t = foo_default())].

We were mirroring serde in its behavior with its default field attribute which uses the field's Default::default. serde also offers a default container attribute but that makes all fields defaulted which wouldn't be appropriate in clap. This is being tracked in #3116.

An unstable Rust feature allows for setting default values on fields directly. We'll need to evaluate how to integrate that into clap as that moves towards stabilization.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@BaumiCoder
Comment options

@epage
Comment options

Answer selected by BaumiCoder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants