Support default field values
Author: epageCreated Dec 10, 2024Updated Sep 22, 2026
LabelsC-enhancementE-mediumA-derive
Default field values would provide an alternative to default_value_t
From the RFC (why is an RFC in 2024 using structopt?)
#[derive(Debug, StructOpt)]
#[structopt(name = "example", about = "An example of StructOpt usage.")]
struct Opt {
/// Set speed
#[structopt(short = "s", long = "speed", default_value_t = 42)]
speed: f64,
...
}default_value_t should have higher precedence
Open questions
- How do we handle this while its nightly only?
- Put it behind a
nightlyfeature?
- Put it behind a
- How do users opt-out of using the default field value?
Source: clap-rs/clap