[Breaking change] Accept raw expression for default values
- Dominant language
- Rust
- Stars
- 2k
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Description
There might be a reason why `default` requires an expression-as-a-string, but I can't think of one. The [reference](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros) has examples of macros doing lots of funky things inside attributes.
It would be nice if someone could write, for example,
```rust
#[derive(FromArgs)]
struct GoUp {
#[argh(option, default = default_height())]
height: usize,
#[argh(option, default = String::from("only up"))]
direction: String,
}
```
The second example in particular is much nicer than what we have to write today,
```rust
#[argh(option, default = "String::from(\"only up\")")]
direction: String,
```
We could even wrap the expression with `Into::into()` in the expansion so it gets even shorter..
```rust
#[argh(option, default = "only up")]
direction: String,
```
The only problem is that this is definitely a breaking change.
One possible soft migration is to add a new attribute `default_expr` which has these semantics.
Contributor guide
Assessment
This issue has not been assessed yet.