Struct netstack3_sync::rc::Primary

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

A primary reference.

Note that only one Primary may be associated with data. This is enforced by not implementing Clone.

For now, this reference is no different than a Strong but later changes will enable blocking the destruction of a primary reference until all strongly held references are dropped.

Implementations§

source§

impl<T> Primary<T>

source

pub fn new(data: T) -> Primary<T>

Returns a new strongly-held reference.

source

pub fn new_cyclic(data_fn: impl FnOnce(Weak<T>) -> T) -> Primary<T>

Constructs a new Primary<T> while giving you a Weak to the allocation, to allow you to construct a T which holds a weak pointer to itself.

Like for [Arc::new_cyclic], the Weak reference provided to data_fn cannot be upgraded until the Primary is constructed.

source

pub fn clone_strong(_: &Self) -> Strong<T>

Clones a strongly-held reference.

source

pub fn downgrade(_: &Self) -> Weak<T>

Returns a weak reference pointing to the same underlying data.

source

pub fn ptr_eq(_: &Self, _: &Strong<T>) -> bool

Returns true if the two pointers point to the same allocation.

source

pub fn debug_id(&self) -> impl Debug

Returns core::fmt::Debug implementation that is stable and unique for the data held behind this Primary.

source

pub fn unwrap(this: Self) -> T

Returns the inner value if no Strong references are held.

§Panics

Panics if Strong references are held when this function is called.

source

pub fn unwrap_with_notifier<N: Notifier<T> + 'static>(this: Self, notifier: N)

Marks this Primary for destruction and uses notifier as a signaler for when destruction of all strong references is terminated. After calling unwrap_with_notifier Weak references can no longer be upgraded.

source

pub fn unwrap_or_notify_with<N: Notifier<T> + 'static, O, F: FnOnce() -> (N, O)>( this: Self, new_notifier: F ) -> Result<T, O>

Marks this Primary for destruction and returns Ok if this was the last strong reference standing for it. Otherwise new_notifier is called to create a new notifier to observe deferred destruction.

Like Primary::unwrap_with_notifier, Weak references can no longer be upgraded after calling unwrap_or_notify_with.

source

pub fn debug_references(this: &Self) -> DebugReferences<T>

Creates a DebugReferences instance.

Trait Implementations§

source§

impl<T> AsRef<T> for Primary<T>

source§

fn as_ref(&self) -> &T

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

impl<T: Debug> Debug for Primary<T>

source§

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

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

impl<T> Deref for Primary<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T> Drop for Primary<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Primary<T>

§

impl<T> RefUnwindSafe for Primary<T>
where T: RefUnwindSafe,

§

impl<T> Send for Primary<T>
where T: Sync + Send,

§

impl<T> Sync for Primary<T>
where T: Sync + Send,

§

impl<T> Unpin for Primary<T>

§

impl<T> UnwindSafe for Primary<T>
where T: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where 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 T
where 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.