Struct deno_core::RcRef

source ·
pub struct RcRef<T> { /* private fields */ }
Expand description

An RcRef encapsulates a reference counted pointer, just like a regular std::rc::Rc. However, unlike a regular Rc, it can be remapped so that it dereferences to any value that’s reachable through the reference-counted pointer. This is achieved through the associated method, RcRef::map(), similar to how std::cell::Ref::map() works. Example:


struct Stuff {
  foo: u32,
  bar: String,
}

let stuff_rc = Rc::new(Stuff {
  foo: 42,
  bar: "hello".to_owned(),
});

// `foo_rc` and `bar_rc` dereference to different types, however
// they share a reference count.
let foo_rc: RcRef<u32> = RcRef::map(stuff_rc.clone(), |v| &v.foo);
let bar_rc: RcRef<String> = RcRef::map(stuff_rc, |v| &v.bar);

Implementations§

source§

impl<T> RcRef<AsyncRefCell<T>>

source

pub fn borrow(&self) -> AsyncRefFuture<T>

source

pub fn borrow_mut(&self) -> AsyncMutFuture<T>

source

pub fn try_borrow(&self) -> Option<AsyncRef<T>>

source

pub fn try_borrow_mut(&self) -> Option<AsyncMut<T>>

source§

impl<T: 'static> RcRef<T>

source

pub fn new(value: T) -> Self

source

pub fn map<S: 'static, R: RcLike<S>, F: FnOnce(&S) -> &T>( source: R, map_fn: F ) -> RcRef<T>

Trait Implementations§

source§

impl<T> AsRef<T> for RcRef<T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> Borrow<T> for RcRef<T>

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> Clone for RcRef<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for RcRef<T>

source§

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

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

impl<T: Default + 'static> Default for RcRef<T>

source§

fn default() -> Self

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

impl<T> Deref for RcRef<T>

§

type Target = T

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<T: 'static> From<&Rc<T, Global>> for RcRef<T>

source§

fn from(rc: &Rc<T>) -> Self

Converts to this type from the input type.
source§

impl<T: 'static> From<&RcRef<T>> for RcRef<T>

source§

fn from(rc_ref: &RcRef<T>) -> Self

Converts to this type from the input type.
source§

impl<T: 'static> From<Rc<T, Global>> for RcRef<T>

source§

fn from(rc: Rc<T>) -> Self

Converts to this type from the input type.
source§

impl<T: 'static> RcLike<T> for &RcRef<T>

source§

impl<T: 'static> RcLike<T> for RcRef<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for RcRef<T>

§

impl<T> !Send for RcRef<T>

§

impl<T> !Sync for RcRef<T>

§

impl<T> Unpin for RcRef<T>

§

impl<T> !UnwindSafe for RcRef<T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.