The Borrow and AsRef traits are very similar in Rust. If I understand correctly, they have the exact same signature (except for the methode name) when being implemented on the same type, the difference lies in how they are used.
But when you take a look at their implementation, for instance on Vec<T> there is a subtle difference:
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Borrow<[T]> for Vec<T> {
fn borrow(&self) -> &[T] {
&self[..]
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> AsRef<[T]> for Vec<T> {
fn as_ref(&self) -> &[T] {
self
}
}
I believe the implementation of AsRef here works thanks to Deref coercion. But couldn't the same mechanism be used for the Borrow implementation ?