- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.8k
Open
Labels
A-lintArea: New lintsArea: New lints
Description
What it does
Looks for impl TryFrom<&str> and suggest impl FromStr instead
Advantage
When parsing a string, FromStr is the idiomatic trait to implement, but that may not be immediately obvious to a Rust novice.
From the docs of TryFrom:
(TryFrom) is useful when you are doing a type conversion that may trivially succeed but may also need special handling
Parsing is something else completely, and for that trait FromStr is to be used.
See also @kangalio's comment on the inverse issue.
Drawbacks
If there is a lifetime on the type, then FromStr won't work, and so we should not make the suggestion in that cade.
Example
impl TryFrom<&str> for MyType {
    type Error = MyError;
    fn try_from(value: &strr) -> Result<Self, Self::Error> {Could be written as:
impl FromStr MyType {
    type Err = MyError;
    fn from_str(value: &strr) -> Result<Self, Self::Err> {Lynnesbian
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lints