google / google/argh

Use the Default trait for enums used as options

Open
#37 2 comments 3 reactions 1 assignee Claimed by @benbrittain View on GitHub
enhancement
Dominant language
Rust
Stars
2k
Forks
102
PR merge metrics
No merged PRs in 30d

Description

It should be possible to use an `enum` as the possible value of an option, without wrapping it in an `Option` when and if the `enum` implements `Default`.

Current example :

```rust
#[derive(argh::FromArgs)]
struct Args {
/// output format
#[argh(option)]
format: Option,
}

let args: Args = argh::from_env();
let format = args.format.unwrap_or_default();
```

Using the Default trait :

```rust
#[derive(argh::FromArgs)]
struct Args {
/// output format
#[argh(option)]
format: OutputFormat, // enum should implement Default
}
```

[Case in my own code, just for context.](https://github.com/jRimbault/ddh/blob/cbcecff97202183bebaacefd5c6d60d51b0551d8/src/main.rs#L8-L37)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.