define default from constant
jeremyandrews opened this issue · comments
I recently switched a project from Structopt to Gumdrop and am generally quite happy with the change. However, one thing I've not been able to figure out how to do is to use a const
to define a default
value.
Essentially, I define a default port and use this in several places in the code:
/// Constant defining Goose's default port when running a Gaggle.
const DEFAULT_PORT: &str = "5115";
One of the places I was able to use it with structopt
was in defining the default value for a couple of run-time configuration options. Is there any way to do this with gumdrop?
For example, if I try this:
/// Sets port Manager listens on
#[options(no_short, default = DEFAULT_PORT, meta = "PORT")]
pub manager_bind_port: u16,
I get the following error:
error: expected literal
--> src/lib.rs:1945:35
|
1945 | #[options(no_short, default = DEFAULT_PORT, meta = "PORT")]
| ^^^^^^^^^^^^
Just a hunch, but what about returning it from an expr default?
I've reworked my codebase so I set defaults manually when not otherwise set, instead of relying on gumdrop for this. It was not because of this issue, it was because I also allow for configurable default overrides. Therefore this issue can be closed if it's not something on the gumdrop roadmap, as this is no longer a concern for me.