Consider this statement: From<T> for U
implies Into<U> for T
. source
let t="abc";
and note that t
has type &str
Everyone has used: let s=String::from(t);
So that we have: From<&str> for String
According to the implication above we have:Into<String> for &str
However, the following does not work:
fn main(){
let z="abc";
let x = String::from(z);
let s=&str::into(x);
}
What am I not understanding?
String::from
does not imply thatString
implements the traitFrom
.let s = &str::into(z);
?String::from()
"? I for one use.to_owned()
, and I know plenty that use.to_string()
or.into()
(but<&str>::into()
is rather uncommon, because why when you can use method syntax instead?)from
associated function do not usually do so because they implement theFrom
trait.