Can a PathBuf argument have a PathBuf default_value_t
option?
#6115
-
For example// Defaults
const FILEPATH: &str = "./urls";
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[arg(
group = "input",
// See error after snippet.
default_value_t = PathBuf::from(FILEPATH),
)]
path: PathBuf,
} The rust-analyzer error is: The trait bound `PathBuf: ToString` is not satisfied
required for `PathBuf` to implement `ToString` So I suspect that this is implying that the default value needs to be Then it would mean that one can only use primitive types assigned to the default? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Anything that implements |
Beta Was this translation helpful? Give feedback.
Anything that implements
Display
can usedefault_value_t
. We insert defaults very early in the parsing process when everything is anOsString
and so we need some way to convert the typed value to anOsString
andDisplay
/ToString
is the most universal way to do so.