# Trait bitflags::__core::borrow::Borrow [−] [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]>`.

If you are implementing `Borrow` and both `Self` and `Borrowed` implement `Hash`, `Eq`, and/or `Ord`, they must produce the same result.

`Borrow` is very similar to, but different than, `AsRef`. See the book for more.

## Required Methods

### `fn borrow(&self) -> &Borrowed`

Immutably borrows from an owned value.

# Examples

    use std::borrow::Borrow;

    fn check<T: Borrow<str>>(s: T) {
        assert_eq!("Hello", s.borrow());
    }

    let s = "Hello".to_string();

    check(s);

    let s = "Hello";

    check(s);

## Implementors

- `impl Borrow for CString`
- `impl Borrow for OsString`
- `impl Borrow for PathBuf`
- `impl<T> Borrow for Box<T> where T: ?Sized`
- `impl Borrow for String`
- `impl<T> Borrow for Rc<T> where T: ?Sized`
- `impl<'a, B> Borrow for Cow<'a, B> where B: ToOwned + ?Sized, B::Owned: 'a`
- `impl<T> Borrow for Vec<T>`
- `impl<T> Borrow for T where T: ?Sized`
- `impl<'a, T> Borrow for &'a T where T: ?Sized`
- `impl<'a, T> Borrow for &'a mut T where T: ?Sized`
- `impl<T> Borrow for [T; 0]`
- `impl<T> Borrow for [T; 1]`
- `impl<T> Borrow for [T; 2]`
- `impl<T> Borrow for [T; 3]`
- `impl<T> Borrow for [T; 4]`
- `impl<T> Borrow for [T; 5]`
- `impl<T> Borrow for [T; 6]`
- `impl<T> Borrow for [T; 7]`
- `impl<T> Borrow for [T; 8]`
- `impl<T> Borrow for [T; 9]`
- `impl<T> Borrow for [T; 10]`
- `impl<T> Borrow for [T; 11]`
- `impl<T> Borrow for [T; 12]`
- `impl<T> Borrow for [T; 13]`
- `impl<T> Borrow for [T; 14]`
- `impl<T> Borrow for [T; 15]`
- `impl<T> Borrow for [T; 16]`
- `impl<T> Borrow for [T; 17]`
- `impl<T> Borrow for [T; 18]`
- `impl<T> Borrow for [T; 19]`
- `impl<T> Borrow for [T; 20]`
- `impl<T> Borrow for [T; 21]`
- `impl<T> Borrow for [T; 22]`
- `impl<T> Borrow for [T; 23]`
- `impl<T> Borrow for [T; 24]`
- `impl<T> Borrow for [T; 25]`
- `impl<T> Borrow for [T; 26]`
- `impl<T> Borrow for [T; 27]`
- `impl<T> Borrow for [T; 28]`
- `impl<T> Borrow for [T; 29]`
- `impl<T> Borrow for [T; 30]`
- `impl<T> Borrow for [T; 31]`
- `impl<T> Borrow for [T; 32]`
- `impl<T> Borrow for Arc<T> where T: ?Sized`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)