Unexpected behaviour of default_value_t
when From<&str>
impl isn't the inverse of Display
impl
#4599
Closed
2 tasks done
Labels
C-bug
Category: Updating dependencies
Please complete the following tasks
Rust Version
1.66.0
Clap Version
4.0.32
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo run
Actual Behaviour
arg
isFoo::Custom("Variant A")
.Expected Behaviour
arg
isFoo::A
.I think the main issue here is a gap between user expectation and actual implementation. What I expected (and I think what most users would expect) is that when I use
default_value_t
,Foo::default
is directly called to fetch the default value.However in reality, it seems like
clap
is doing a "roundtrip" to string and back whendefault_value_t
is used. The default argument goes fromFoo
toString
viaDisplay
, then back toFoo
viaFrom<&str>
.The problem with this, is that it assumes
Foo::from::<&str>
is the inverse operation ofFoo::to_string
, when that's not necessarily the case. In which case strange behaviour like this suddenly pop up.So in my amateur opinion, either:
default_value_t
should be changed to useFoo::default
directly (this is the ideal solution, but I don't know whether this will be difficult to implement),Foo::from::<&str>
should be the inverse operation ofFoo::to_string
The text was updated successfully, but these errors were encountered: