Struct lucia_lang::gc::Ref
source · pub struct Ref<'a, T: ?Sized + 'a> { /* private fields */ }Expand description
Wraps a borrowed reference to a value in a RefCell box.
A wrapper type for an immutably borrowed value from a RefCell<T>.
Implementations§
source§impl<'a, T: ?Sized> Ref<'a, T>
impl<'a, T: ?Sized> Ref<'a, T>
sourcepub fn clone(orig: &Ref<'a, T>) -> Ref<'a, T>
pub fn clone(orig: &Ref<'a, T>) -> Ref<'a, T>
Copies a Ref.
The RefCell is already immutably borrowed, so this cannot fail.
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 r.borrow().clone() to clone the contents of
a RefCell.
sourcepub fn map<U: ?Sized, F>(orig: Ref<'a, T>, f: F) -> Ref<'a, U>where
F: FnOnce(&T) -> &U,
pub fn map<U: ?Sized, F>(orig: Ref<'a, T>, f: F) -> Ref<'a, U>where F: FnOnce(&T) -> &U,
Makes a new Ref for a component of the borrowed data.
The RefCell is already immutably borrowed, so this cannot fail.
This is an associated function that needs to be used as Ref::map(...).
A method would interfere with methods of the same name on the contents
of a RefCell used through Deref.
sourcepub fn filter_map<U: ?Sized, F>(
orig: Ref<'a, T>,
f: F
) -> Result<Ref<'a, U>, Self>where
F: FnOnce(&T) -> Option<&U>,
pub fn filter_map<U: ?Sized, F>( orig: Ref<'a, T>, f: F ) -> Result<Ref<'a, U>, Self>where F: FnOnce(&T) -> Option<&U>,
Makes a new Ref for an optional component of the borrowed data. The
original guard is returned as an Err(..) if the closure returns
None.
The RefCell is already immutably borrowed, so this cannot fail.
This is an associated function that needs to be used as
Ref::filter_map(...). A method would interfere with methods of the same
name on the contents of a RefCell used through Deref.
sourcepub fn map_split<U: ?Sized, V: ?Sized, F>(
orig: Ref<'a, T>,
f: F
) -> (Ref<'a, U>, Ref<'a, V>)where
F: FnOnce(&T) -> (&U, &V),
pub fn map_split<U: ?Sized, V: ?Sized, F>( orig: Ref<'a, T>, f: F ) -> (Ref<'a, U>, Ref<'a, V>)where F: FnOnce(&T) -> (&U, &V),
Splits a Ref into multiple Refs for different components of the
borrowed data.
The RefCell is already immutably borrowed, so this cannot fail.
This is an associated function that needs to be used as
Ref::map_split(...). A method would interfere with methods of the same
name on the contents of a RefCell used through Deref.