Struct task_notify::Notify

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

A wrapper which wakes tasks on mutable accesses to the wrapped value.

This can be used to transparently notify an asyncronous task that it should, for example, check for more work in a queue or try again to acquire a lock.

Importantly: only DerefMut is used to wake the target task. Read-only access is possible without causing wake events. If no Waker has been registered yet, no task will be woken.

Implementations§

source§

impl<T> Notify<T>

source

pub fn new(inner: T) -> Self

source

pub fn has_waker(ptr: &Notify<T>) -> bool

Check whether or not this Notify has a registered Waker.

This function is implemented as an associated function rather than a method to avoid conflicts with methods on the wrapped type. Call it as Notify::has_waker().

source

pub fn waker(ptr: &mut Notify<T>) -> Option<Waker>

Get a copy of the registered Waker for this Notify.

This function is implemented as an associated function rather than a method to avoid conflicts with methods on the wrapped type. Call it as Notify::waker().

source

pub fn wake(ptr: &mut Notify<T>)

Call wake on the waker, if it’s a waker, yehaa!

source

pub fn register_waker(ptr: &mut Notify<T>, waker: &Waker)

Register a Waker to be woken upon mutable accesses to the wrapped value.

This function is implemented as an associated function rather than a method to avoid conflicts with methods on the wrapped type. Call it as Notify::register_waker().

Panics

Panics if there is an already registered Waker. Use Notify::has_waker to check the state before using this.

source

pub fn clear_waker(ptr: &mut Notify<T>) -> Option<Waker>

Removes and returns the Waker registered to this Notify.

This function is implemented as an associated function rather than a method to avoid conflicts with methods on the wrapped type. Call it as Notify::clear_waker().

source

pub fn into_inner(ptr: Notify<T>) -> T

Consumes the Notify, dropping any associated Waker and returning the inner value without notifying the Waker.

This function is implemented as an associated function rather than a method to avoid conflicts with methods on the wrapped type. Call it as Notify::into_inner().

Trait Implementations§

source§

impl<T: Clone> Clone for Notify<T>

source§

fn clone(&self) -> Notify<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Notify<T>

source§

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

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

impl<T: Default> Default for Notify<T>

source§

fn default() -> Notify<T>

Returns the “default value” for a type. Read more
source§

impl<T> Deref for Notify<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T> DerefMut for Notify<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

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

§

impl<T> Send for Notify<T>where T: Send,

§

impl<T> Sync for Notify<T>where T: Sync,

§

impl<T> Unpin for Notify<T>where T: Unpin,

§

impl<T> UnwindSafe for Notify<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.