Open
Description
What it does
Checks for functions and methods that could be a From
impl (we could even do this for TryFrom
)
Advantage
- Makes the code more idiomatic
Drawbacks
No response
Example
struct StructA {
some_field: String
}
struct StructB {
some_field: String
}
fn map_to_struct_b(a: StructA) -> StructB {
StructB {
some_field: a.some_field
}
}
impl StructA {
fn to_struct_b(self) -> StructB {
StructB {
some_field: self.some_field
}
}
}
Could be written as:
impl From<StructA> for StructB {
fn from(a: StructA) -> Self {
StructB {
some_field: a.some_field
}
}
}