The standard library contains this code:
// From implies Into
#[stable(feature = "rust1", since = "1.0.0")]
impl<T, U> Into<U> for T where U: From<T> {
fn into(self) -> U {
U::from(self)
}
}
So, you basically only ever implement From, and you get the equivalent Into for free.More specifically, you would usually use `Into` to bound a generic function:
fn is_hello<T: Into<Vec<u8>>>(s: T) {
let bytes = b"hello".to_vec();
assert_eq!(bytes, s.into());
}
let s = "hello".to_string();
is_hello(s);
Whereas you'd use From to perform a conversion: let string = "hello".to_string();
let other_string = String::from("hello");
assert_eq!(string, other_string);
These APIs are pretty new; they landed _right_ before beta happened. We used to have FromFoo traits, and this generic system replaced them.