netstack3_sync::rc

Struct 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>

Source§

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

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>,

Source§

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.
Source§

impl<L, T> UnlockedAccess<L> for T

Source§

type Data = <L as UnlockedAccessMarkerFor<T>>::Data

The type of state being accessed.
Source§

type Guard<'l> = &'l <L as UnlockedAccessMarkerFor<T>>::Data where T: 'l

A guard providing read access to the data.
Source§

fn access(&self) -> <T as UnlockedAccess<L>>::Guard<'_>

How to access the state.
Source§

impl<B, A> LockBefore<B> for A
where B: LockAfter<A>,