Struct async_winit::Handler

source ·
pub struct Handler<T: Event> { /* private fields */ }
Expand description

An event handler.

This type is used to receive events from the GUI system. Whenever an event occurs, it is sent to all of the listeners of the corresponding event type. The listeners can then process the event asynchronously.

There are four ways to listen to events:

  • Using the wait_once() function, which waits for a single instance of the event. However, there is a race condition where it can miss events in multithreaded environments where the event occurs between the time the event is received and the time the listener is registered. To avoid this, use one of the other methods. However, this method is the most efficient.
  • Using the wait_many() stream, which asynchronously iterates over events.
  • Using the wait_direct[_async]() function, which runs a closure in the event handler. This is good for use cases like drawing.
  • Using the wait_guard() function, which forces the event handler to stop until the event has been completely processed. This is good for use cases like handling suspends.

This type does not allocate unless you use any waiting functions; therefore, you only pay overhead for events that you use.

Implementations§

source§

impl<T: Event> Handler<T>

source

pub fn wait_once(&self) -> WaitOnce<T>

Wait for the next event.

source

pub fn wait_many(&self) -> WaitMany<T>

A stream over received events.

source

pub async fn wait_direct_async<Fut: Future<Output = bool> + Send + 'static, F: FnMut(&mut T::Unique<'_>) -> Fut + Send + 'static>( &self, f: F ) -> usize

Register an async closure be called when the event is received.

source

pub async fn wait_direct( &self, f: impl FnMut(&mut T::Unique<'_>) -> bool + Send + 'static ) -> usize

Register a closure be called when the event is received.

source

pub async fn remove_direct(&self, id: usize)

Remove a direct listener.

source

pub fn wait_guard(&self) -> WaitGuard<'_, T>

A guard that prevents the event handler from returning before it is processed.

Trait Implementations§

source§

impl<T: Event> Drop for Handler<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T: Event> Future for &Handler<T>

§

type Output = <T as EventSealed>::Clonable

The type of value produced on completion.
source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
source§

impl<T: Event> Future for Handler<T>

§

type Output = <T as EventSealed>::Clonable

The type of value produced on completion.
source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
source§

impl<T: Event> Unpin for Handler<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Handler<T>

§

impl<T> Send for Handler<T>

§

impl<T> Sync for Handler<T>

§

impl<T> !UnwindSafe for Handler<T>

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<F> FutureExt for Fwhere F: Future + ?Sized,

source§

fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output>where Self: Unpin,

A convenience for calling Future::poll() on !Unpin types.
source§

fn or<F>(self, other: F) -> Or<Self, F>where Self: Sized, F: Future<Output = Self::Output>,

Returns the result of self or other future, preferring self if both are ready. Read more
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<F> IntoFuture for Fwhere F: Future,

§

type Output = <F as Future>::Output

The output that the future will produce on completion.
§

type IntoFuture = F

Which kind of future are we turning this into?
source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. 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.
§

impl<F, T, E> TryFuture for Fwhere F: Future<Output = Result<T, E>> + ?Sized,

§

type Ok = T

The type of successful values yielded by this future
§

type Error = E

The type of failures yielded by this future
§

fn try_poll( self: Pin<&mut F>, cx: &mut Context<'_> ) -> Poll<<F as Future>::Output>

Poll this TryFuture as if it were a Future. Read more
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.