Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default field values #5839

Open
epage opened this issue Dec 10, 2024 · 2 comments
Open

Support default field values #5839

epage opened this issue Dec 10, 2024 · 2 comments
Labels
A-derive Area: #[derive]` macro API C-enhancement Category: Raise on the bar on expectations E-medium Call for participation: Experience needed to fix: Medium / intermediate

Comments

@epage
Copy link
Member

epage commented Dec 10, 2024

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 nightly feature?
  • How do users opt-out of using the default field value?
@epage epage added C-enhancement Category: Raise on the bar on expectations E-medium Call for participation: Experience needed to fix: Medium / intermediate A-derive Area: #[derive]` macro API labels Dec 10, 2024
@jhpratt
Copy link

jhpratt commented Dec 10, 2024

why is an RFC in 2024 using structopt?

The RFC work started in 2018 😅

@jalil-salame
Copy link
Contributor

I don't see a use for different default_value_t and a struct default's value, so I would fire a warning/deny by default lint ideally (I'd love a compiler_warning!() macro)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-derive Area: #[derive]` macro API C-enhancement Category: Raise on the bar on expectations E-medium Call for participation: Experience needed to fix: Medium / intermediate
Projects
None yet
Development

No branches or pull requests

3 participants