Struct Ref

Source
pub struct Ref<'b, T: ?Sized, Tk: Token + ?Sized = BoxToken> { /* private fields */ }
Expand description

A wrapper type for an immutably borrowed value from a TokenRefCell.

The token used for borrowing synchronization is also borrowed. Dedicated methods allows reusing the token for further borrowing.

Implementations§

Source§

impl<'b, T: ?Sized, Tk: Token + ?Sized> Ref<'b, T, Tk>

Source

pub fn into_ref(self) -> &'b T

Unwraps the inner reference.

Examples found in repository?
examples/graph.rs (line 30)
29    pub fn get_node(&self, id: NodeId) -> Option<&Node> {
30        Some(self.nodes.get(&id)?.borrow(&self.token).into_ref())
31    }
Source

pub fn clone(this: &Self) -> Self

Copies a Ref.

This is an associated function that needs to be used as Ref::clone(...). A Clone implementation or a method would interfere with the widespread use of cell.borrow(&token).clone() to clone the contents of a TokenRefCell.

Source

pub fn reborrow<U: ?Sized>( &self, cell: impl FnOnce(&T) -> &TokenRefCell<U, Tk>, ) -> Ref<'_, U, Tk>

Uses borrowed token shared reference to reborrow a TokenRefCell.

§Panics

See TokenRefCell::borrow.

Source

pub fn try_reborrow<U: ?Sized>( &self, cell: impl FnOnce(&T) -> &TokenRefCell<U, Tk>, ) -> Result<Ref<'_, U, Tk>, BorrowError>

Uses borrowed token shared reference to reborrow a TokenRefCell.

See TokenRefCell::try_borrow.

Source

pub fn reborrow_opt<U: ?Sized>( &self, cell: impl FnOnce(&T) -> Option<&TokenRefCell<U, Tk>>, ) -> Option<Ref<'_, U, Tk>>

Uses borrowed token shared reference to optionally reborrow a TokenRefCell.

§Panics

See TokenRefCell::borrow.

Source

pub fn try_reborrow_opt<U: ?Sized>( &self, cell: impl FnOnce(&T) -> Option<&TokenRefCell<U, Tk>>, ) -> Option<Result<Ref<'_, U, Tk>, BorrowError>>

Uses borrowed token shared reference to optionally reborrow a TokenRefCell.

See TokenRefCell::try_borrow.

Source

pub fn reborrow_stateful<'a, S>( &'a self, state: impl FnOnce(&'a T) -> S, ) -> Reborrow<'a, S, Tk>

Wraps the borrowed token shared reference into a stateful Reborrow instance.

It can be used for example to reborrow cells from an iterator.

Source

pub fn token_id(&self) -> Tk::Id

Get the id of the borrowed token.

Trait Implementations§

Source§

impl<T: ?Sized + Debug, Tk: Token + ?Sized> Debug for Ref<'_, T, Tk>
where Tk::Id: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized, Tk: Token + ?Sized> Deref for Ref<'_, T, Tk>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized + Display, Tk: Token + ?Sized> Display for Ref<'_, T, Tk>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'b, T, Tk> Freeze for Ref<'b, T, Tk>
where <Tk as Token>::Id: Freeze, T: ?Sized, Tk: ?Sized,

§

impl<'b, T, Tk> RefUnwindSafe for Ref<'b, T, Tk>
where <Tk as Token>::Id: RefUnwindSafe, T: RefUnwindSafe + ?Sized, Tk: RefUnwindSafe + ?Sized,

§

impl<'b, T, Tk> Send for Ref<'b, T, Tk>
where <Tk as Token>::Id: Send, T: Sync + ?Sized, Tk: Sync + ?Sized,

§

impl<'b, T, Tk> Sync for Ref<'b, T, Tk>
where <Tk as Token>::Id: Sync, T: Sync + ?Sized, Tk: Sync + ?Sized,

§

impl<'b, T, Tk> Unpin for Ref<'b, T, Tk>
where <Tk as Token>::Id: Unpin, T: ?Sized, Tk: ?Sized,

§

impl<'b, T, Tk> UnwindSafe for Ref<'b, T, Tk>
where <Tk as Token>::Id: UnwindSafe, T: RefUnwindSafe + ?Sized, Tk: RefUnwindSafe + ?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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.