Skip to content

Support non-Display types with default_value_t #4558

@rdelfin

Description

@rdelfin

Please complete the following tasks

Clap Version

4.0.29

Describe your use case

Currently, there's no way (that I can figure out) to set a default value on a PathBuf using derive. You can see a minimal reproducible example here. The specific error is:

error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): `PathBuf` doesn't implement `std::fmt::Display`
 --> src/main.rs:6:24
  |
6 |     #[arg(short, long, default_value_t = PathBuf::from("/some/default/path"))]
  |                        ^^^^^^^^^^^^^^^ `PathBuf` cannot be formatted with the default formatter; call `.display()` on it
  |
  = help: the trait `std::fmt::Display` is not implemented for `PathBuf`
  = note: call `.display()` or `.to_string_lossy()` to safely print paths, as they may contain non-Unicode data
  = note: required for `PathBuf` to implement `ToString`

Describe the solution you'd like

Ideally, either logic to allow for PathBufs to display correctly with the .display() call, or a way of suplementing default values let you write a custom display string.

Alternatives, if applicable

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-deriveArea: #[derive]` macro APIC-enhancementCategory: Raise on the bar on expectationsS-waiting-on-designStatus: Waiting on user-facing design to be resolved before implementing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions