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
sourceimpl<T> RcRef<AsyncRefCell<T>>
impl<T> RcRef<AsyncRefCell<T>>
pub fn borrow(&self) -> AsyncRefFuture<T>
pub fn borrow_mut(&self) -> AsyncMutFuture<T>
pub fn try_borrow(&self) -> Option<AsyncRef<T>>
pub fn try_borrow_mut(&self) -> Option<AsyncMut<T>>
Trait Implementations
impl<T: 'static> RcLike<T> for &RcRef<T>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more