loan_cell

Struct LoanCell

Source
pub struct LoanCell<T: ?Sized>(/* private fields */);
Expand description

A cell that allows lending a reference to a value for a limited scope.

See the module-level documentation for more information.

Implementations§

Source§

impl<T: ?Sized> LoanCell<T>

Source

pub const fn new() -> Self

Creates a LoanCell with no loaned data.

Source

pub fn lend<R>(&self, value: &T, f: impl FnOnce() -> R) -> R

Lends value for the lifetime of f. f or any function it calls can access the loaned value via LoanCell::borrow.

If a value is already lent, it is replaced with value for the duration of f and restored afterwards.

Source

pub fn is_lent(&self) -> bool

Returns true if a value is currently lent.

Source

pub fn borrow<R>(&self, f: impl FnOnce(Option<&T>) -> R) -> R

Borrows the lent value for the duration of f. If no value is currently lent, f is called with None.

Trait Implementations§

Source§

impl<T: Default + ?Sized> Default for LoanCell<T>

Source§

fn default() -> LoanCell<T>

Returns the “default value” for a type. Read more
Source§

impl<T: RefUnwindSafe + ?Sized> RefUnwindSafe for LoanCell<T>

Source§

impl<T: RefUnwindSafe + ?Sized> UnwindSafe for LoanCell<T>

Auto Trait Implementations§

§

impl<T> !Freeze for LoanCell<T>

§

impl<T> !Send for LoanCell<T>

§

impl<T> !Sync for LoanCell<T>

§

impl<T> Unpin for LoanCell<T>
where T: ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.