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

Custom default value for skipped fields #256

Closed
CreepySkeleton opened this issue Sep 17, 2019 · 1 comment · Fixed by #260
Closed

Custom default value for skipped fields #256

CreepySkeleton opened this issue Sep 17, 2019 · 1 comment · Fixed by #260
Labels
enhancement We would love to have this feature! Feel free to supply a PR

Comments

@CreepySkeleton
Copy link
Collaborator

CreepySkeleton commented Sep 17, 2019

I propose support for explicit default values for skipped fields:

#[derive(StructOpt)]
pub struct Opt {
    #[structopt(long, short)]
    number: u32,

    #[structopt(skip = "key")]
    k: String,

    #[structopt(skip = &[1, 2, 3])]
    v: Vec<u32>,
}

The syntax is skip = expr, the field will be assigned with (expr).into() instead of Default::default().

@TeXitoi TeXitoi added the enhancement We would love to have this feature! Feel free to supply a PR label Sep 17, 2019
@TeXitoi
Copy link
Owner

TeXitoi commented Sep 17, 2019

OK for such a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement We would love to have this feature! Feel free to supply a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants