Skip to content

define default from constant #43

@jeremyandrews

Description

@jeremyandrews

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")]
     |                                   ^^^^^^^^^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions