Mediator

Struct Mediator 

Source
pub struct Mediator<T, E> { /* private fields */ }
Expand description

A mediator is a central hub for communication between futures.

Implementations§

Source§

impl<T, E> Mediator<T, E>

Source

pub fn new(value: T) -> Self

Create new mediator with shared value.

Source

pub async fn with<F, R>(&self, f: F) -> R
where F: FnOnce(&T) -> R,

Acquire the lock and access immutable shared data.

Source

pub async fn with_mut<F, R>(&self, f: F) -> R
where F: FnOnce(&mut T) -> R,

Acquire the lock and access mutable shared data.

Source

pub fn try_lock(&self) -> Option<MutexGuard<'_, Shared<T, E>>>

Attempt to acquire the shared data lock immediately.

If the lock is currently held, this will return None.

Source

pub async fn notify(&self, event: E)
where E: Eq + Hash + Debug,

Emit one event on.

Source

pub async fn notify_all<Events: AsRef<[E]>>(&self, events: Events)
where E: Eq + Hash + Clone + Debug,

Emit all events

Source

pub fn on_fn<F, R>(&self, event: E, f: F) -> OnEvent<T, E, F>
where F: FnMut(&mut Shared<T, E>, &mut Context<'_>) -> Poll<R> + Unpin, T: Unpin + 'static, E: Unpin + Eq + Hash + Debug, R: Unpin,

Create a new event handle future with poll function f and run once immediately

If f returns Pending, the system will move the handle into the event waiting map, and the future returns Pending status.

You can call notify to wake up this poll function and run once again.

Trait Implementations§

Source§

impl<T, E> Clone for Mediator<T, E>

Source§

fn clone(&self) -> Self

Returns a duplicate 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, E: Debug> Debug for Mediator<T, E>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, E> Freeze for Mediator<T, E>

§

impl<T, E> !RefUnwindSafe for Mediator<T, E>

§

impl<T, E> Send for Mediator<T, E>
where T: Send, E: Send,

§

impl<T, E> Sync for Mediator<T, E>
where T: Send, E: Send,

§

impl<T, E> Unpin for Mediator<T, E>

§

impl<T, E> !UnwindSafe for Mediator<T, E>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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