Open Stukalov-A-M opened 1 month ago
Implemented From<&str>
, replace parse to &str
@Stukalov-A-M str::parse<T>
is more convenient than Into<T>::into
in cases where type inference fails, thanks to the turbofish syntax. It is also more idiomatic in this case: FromStr
carries the intent of extracting meaning from a string, while (Try)From
is more suited for type conversions, where the string probably stays the same but the context around it is changed.
@Stukalov-A-M
str::parse<T>
is more convenient thanInto<T>::into
in cases where type inference fails, thanks to the turbofish syntax. It is also more idiomatic in this case:FromStr
carries the intent of extracting meaning from a string, while(Try)From
is more suited for type conversions, where the string probably stays the same but the context around it is changed.
Could u pls. send the ref where it's said about idiomaticity ?
I found only info that parse::
Here are some discussions on it:
If the parsing is infallible, it's possible to specify the empty Infallible
type as the Err
associated type in FromStr
.
Here are some discussions on it:
- https://users.rust-lang.org/t/is-there-actually-a-semantic-difference-between-fromstr-and-tryfrom-str/92765/2
- https://internals.rust-lang.org/t/pre-rfc-deprecate-fromstr-in-favor-of-tryfrom-str/12331/5
If the parsing is infallible, it's possible to specify the empty
Infallible
type as theErr
associated type inFromStr
.
Thanks a lot! I'll research the discussions.
It's best to use the inherent
str::parse<T: FromStr>
method across the project instead ofFromStr::from_str
since it doesn't require bringingFromStr
into the scope.