std::borrow

This module is used for working with borrowed data.

enum Cow (clone-on-write smarter pointer)

The Cow allows for immutable access to borrowed data (and can enclose this data) and permits cloning lazily when mutation or ownership is required. It is designed to work using the Borrow trait. It also implements Deref, which will allow access to non-mutating methods on the data Cow has enclosed. to_mut will provide a mutable reference to the owned value.

 

  • Trait std::borrow::Borrow: Data can be borrowed in a number of different ways: shared borrowing (T and &T), mutable borrowing (&mut T), and borrowed slices from the likes of Vec<T> (&[T], and &mut[T]).
    The Borrow trait provides a convenient method to abstract over the given type. For example: T: Borrow<U> means that &U is borrowed from &T
    • fn borrow(&self) -> &Borrowed: Immutably borrows from an owned value
  • Trait std::borrow::BorrowMut: Used for mutably borrowing data

    • fn borrow_mut(&mut self) -> &mut Borrowed: Mutably borrows from an owned value
  • Trait std::borrow:ToOwned: A generalization of Clone for borrowing data. Clone only works when going from &T to T. ToOwned generalizes Clone to construct owned data from any borrow of a given type.

    • fn to_owned(&self) -> Self::Owned: Creates owned data from borrowed data
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset