/// 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<T>`] as more types can safely implement it.
///
/// [`Borrow<T>`]: trait.Borrow.html
#[stable(feature = "rust1", since = "1.0.0")]
-pub trait BorrowMut<Borrowed: ?Sized> : Borrow<Borrowed> {
+pub trait BorrowMut<Borrowed: ?Sized>: Borrow<Borrowed> {
/// Mutably borrows from an owned value.
///
/// # Examples
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Borrow<T> for T {
- fn borrow(&self) -> &T { self }
+ fn borrow(&self) -> &T {
+ self
+ }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> BorrowMut<T> 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<T: ?Sized> Borrow<T> for &T {
- fn borrow(&self) -> &T { &**self }
+ fn borrow(&self) -> &T {
+ &**self
+ }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Borrow<T> for &mut T {
- fn borrow(&self) -> &T { &**self }
+ fn borrow(&self) -> &T {
+ &**self
+ }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> BorrowMut<T> for &mut T {
- fn borrow_mut(&mut self) -> &mut T { &mut **self }
+ fn borrow_mut(&mut self) -> &mut T {
+ &mut **self
+ }
}