I'm trying to figure out if libraries should implement both
TryFrom<&str> for types that can be created from strings. For now I think they should and don't think there is a semantic difference between them. However there's a blogpost which claims there is and I found people both agreeing and disagreeing. What does wider Rust community think?
FromStrwas created before
TryFrom, which is an indication that
TryFromis superior because it's more general and flexible
- I remember discussions about
impl<'a, T: FromStr> TryFrom<&'a str> for Tand deprecating
FromStrbut it didn't happen because it would conflict with
impl<U, T: Into<U>> TryFrom<T> for Uwhich was more important.
- Including also
TryFrom<String>can avoid allocations in some cases and it makes sense to also have
TryFrom<&str>allows borrowing the input which may be useful for types containing
stddocumentation doesn't say anything about it but it does mention semantic differences of other traits that are similar to each-other (e.g.
fmt::Write); could be just documentation issue though