Trait std::borrow::BorrowStable
[-] [+]
[src]
pub trait Borrow<Borrowed> where Borrowed: ?Sized {
fn borrow(&self) -> &Borrowed;
}
A trait for borrowing data.
In general, there may be several ways to "borrow" a piece of data. The
typical ways of borrowing a type T
are &T
(a shared borrow) and &mut T
(a mutable borrow). But types like Vec<T>
provide additional kinds of
borrows: the borrowed slices &[T]
and &mut [T]
.
When writing generic code, it is often desirable to abstract over all ways
of borrowing data from a given type. That is the role of the Borrow
trait: if T: Borrow<U>
, then &U
can be borrowed from &T
. A given
type can be borrowed as multiple different types. In particular, Vec<T>:
Borrow<Vec<T>>
and Vec<T>: Borrow<[T]>
.
Required Methods
fn borrow(&self) -> &Borrowed
Immutably borrow from an owned value.
Implementors
impl<T> Borrow<[T]> for Vec<T>
impl Borrow<str> for String
impl<T> Borrow<T> for T where T: ?Sized
impl<'a, T> Borrow<T> for &'a T where T: ?Sized
impl<'a, T> Borrow<T> for &'a mut T where T: ?Sized
impl<T> Borrow<T> for Rc<T>
impl<T> Borrow<T> for Arc<T>
impl<'a, B> Borrow<B> for Cow<'a, B> where B: ToOwned, <B as ToOwned>::Owned: 'a, B: ?Sized
impl Borrow<OsStr> for OsString
impl Borrow<Path> for PathBuf