[−][src]Struct static_alloc::rc::Weak
A reference-counting pointer to the allocation of an Rc
.
TODO
Evaluate an interface:
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 static_alloc::{rc, Slab}; struct Foo; let slab: Slab<[u8; 1024]> = Slab::uninit(); let rc = slab.rc(Foo).unwrap(); let (_, weak) = rc::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 static_alloc::{rc, Slab}; let memory: Slab<[u8; 1024]> = Slab::uninit(); let rc = memory.rc(0usize).unwrap(); let weak = rc::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 static_alloc::{rc, Slab}; struct Foo; let slab: Slab<[u8; 1024]> = Slab::uninit(); let rc = slab.rc(Foo).unwrap(); let (_, weak) = rc::Rc::try_unwrap(rc).ok().unwrap(); // We just destroyed the only one. assert_eq!(rc::Weak::strong_count(&weak), 0);
pub fn weak_count(&self) -> usize
[src]
Gets the number of weak pointers pointing at the value.
Example
use static_alloc::{rc, Slab}; struct Foo; let slab: Slab<[u8; 1024]> = Slab::uninit(); let rc = slab.rc(Foo).unwrap(); let (_, weak) = rc::Rc::try_unwrap(rc).ok().unwrap(); // This is the only one pointing at the allocation. assert_eq!(rc::Weak::weak_count(&weak), 1);
Trait Implementations
impl<'_, T> Drop for Weak<'_, T>
[src]
impl<'_, T> Clone for Weak<'_, T>
[src]
fn clone(&self) -> Self
[src]
Clone the Weak
.
This will increment the weak reference count.
Examples
use static_alloc::{rc, Slab}; struct Foo; let slab: Slab<[u8; 1024]> = Slab::uninit(); let foo = slab.rc(Foo).unwrap(); let (_, weak) = rc::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]
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl<'a, T> Unpin for Weak<'a, T> where
T: Unpin,
T: Unpin,
impl<'a, T> !Sync for Weak<'a, T>
impl<'a, T> !Send for Weak<'a, T>
Blanket Implementations
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> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,