X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibcore%2Fborrow.rs;h=3e533255becb5e48a86dd72a5e32686c76ff642a;hb=cdbbc25cc31080e189a98c010a0b39a9074d0c50;hp=89668dc06505b4cb7689a25ccbe2b4c6270bb356;hpb=ccba43df81d5bda37c9e4d231ad4443e6f3a7e44;p=rust.git diff --git a/src/libcore/borrow.rs b/src/libcore/borrow.rs index 89668dc0650..3e533255bec 100644 --- a/src/libcore/borrow.rs +++ b/src/libcore/borrow.rs @@ -32,6 +32,10 @@ /// on the identical behavior of these additional trait implementations. /// These traits will likely appear as additional trait bounds. /// +/// In particular `Eq`, `Ord` and `Hash` must be equivalent for +/// borrowed and owned values: `x.borrow() == y.borrow()` should give the +/// same result as `x == y`. +/// /// If generic code merely needs to work for all types that can /// provide a reference to related type `T`, it is often better to use /// [`AsRef`] as more types can safely implement it. @@ -185,7 +189,7 @@ pub trait Borrow { /// /// [`Borrow`]: trait.Borrow.html #[stable(feature = "rust1", since = "1.0.0")] -pub trait BorrowMut : Borrow { +pub trait BorrowMut: Borrow { /// Mutably borrows from an owned value. /// /// # Examples @@ -207,25 +211,35 @@ pub trait BorrowMut : Borrow { #[stable(feature = "rust1", since = "1.0.0")] impl Borrow for T { - fn borrow(&self) -> &T { self } + fn borrow(&self) -> &T { + self + } } #[stable(feature = "rust1", since = "1.0.0")] impl BorrowMut for T { - fn borrow_mut(&mut self) -> &mut T { self } + fn borrow_mut(&mut self) -> &mut T { + self + } } #[stable(feature = "rust1", since = "1.0.0")] impl Borrow for &T { - fn borrow(&self) -> &T { &**self } + fn borrow(&self) -> &T { + &**self + } } #[stable(feature = "rust1", since = "1.0.0")] impl Borrow for &mut T { - fn borrow(&self) -> &T { &**self } + fn borrow(&self) -> &T { + &**self + } } #[stable(feature = "rust1", since = "1.0.0")] impl BorrowMut for &mut T { - fn borrow_mut(&mut self) -> &mut T { &mut **self } + fn borrow_mut(&mut self) -> &mut T { + &mut **self + } }