[−][src]Struct without_alloc::rc::Weak
A reference-counting pointer to the allocation of an Rc.
TODO
Evaluate an interface:
ⓘThis example is not tested
fn reinit(&self, val: T) -> Result<Rc<T>, T>;
Methods
impl<'a, T> Weak<'a, T>[src]
pub fn try_unwrap(self) -> Result<Uninit<'a, ()>, Self>[src]
Try to unwrap the original allocation of the Rc.
This will only work when this is the only pointer to the allocation. That is, there are
neither Weak nor Rc still pointing at it.
Example
use without_alloc::{alloc::LocalAllocLeakExt, rc::Rc}; use static_alloc::Bump; struct Foo; let slab: Bump<[u8; 1024]> = Bump::uninit(); let rc = slab.rc(Foo).unwrap(); let (_, weak) = Rc::try_unwrap(rc).ok().unwrap(); // This is the only one pointing at the allocation. let memory = weak.try_unwrap().ok().unwrap();
pub fn upgrade(&self) -> Option<Rc<'a, T>>[src]
Attempt to upgrade to a shared pointer to the value.
This operation will only succeed if there are still strong pointers to the value, i.e.
strong_count is not zero. Then the value has not been dropped yet and its lifetime is
extended.
use without_alloc::{alloc::LocalAllocLeakExt, rc::Rc}; use static_alloc::Bump; let memory: Bump<[u8; 1024]> = Bump::uninit(); let rc = memory.rc(0usize).unwrap(); let weak = Rc::downgrade(&rc); let rc2 = weak.upgrade().unwrap(); drop(rc); drop(rc2); // No more strong pointers left. assert!(weak.upgrade().is_none());
impl<'_, T> Weak<'_, T>[src]
pub fn strong_count(&self) -> usize[src]
Gets the number of strong pointers pointing at the value.
Example
use without_alloc::{alloc::LocalAllocLeakExt, rc::Rc, rc::Weak}; use static_alloc::Bump; struct Foo; let slab: Bump<[u8; 1024]> = Bump::uninit(); let rc = slab.rc(Foo).unwrap(); let (_, weak) = Rc::try_unwrap(rc).ok().unwrap(); // We just destroyed the only one. assert_eq!(Weak::strong_count(&weak), 0);
pub fn weak_count(&self) -> usize[src]
Gets the number of weak pointers pointing at the value.
Example
use without_alloc::{alloc::LocalAllocLeakExt, rc::Rc, rc::Weak}; use static_alloc::Bump; struct Foo; let slab: Bump<[u8; 1024]> = Bump::uninit(); let rc = slab.rc(Foo).unwrap(); let (_, weak) = Rc::try_unwrap(rc).ok().unwrap(); // This is the only one pointing at the allocation. assert_eq!(Weak::weak_count(&weak), 1);
Trait Implementations
impl<'_, T> Clone for Weak<'_, T>[src]
fn clone(&self) -> Self[src]
Clone the Weak.
This will increment the weak reference count.
Examples
use without_alloc::{alloc::LocalAllocLeakExt, rc::Rc}; use static_alloc::Bump; struct Foo; let slab: Bump<[u8; 1024]> = Bump::uninit(); let foo = slab.rc(Foo).unwrap(); let (_, weak) = Rc::try_unwrap(foo).ok().unwrap(); assert_eq!(weak.weak_count(), 1); let weak2 = weak.clone(); assert_eq!(weak.weak_count(), 2); assert_eq!(weak2.weak_count(), 2);
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl<'_, T> Drop for Weak<'_, T>[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,