pub struct Handler<T: Event, TS: ThreadSafety> { /* 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§
Trait Implementations§
Source§impl<'a, T: Event, TS: ThreadSafety> IntoFuture for &'a Handler<T, TS>
impl<'a, T: Event, TS: ThreadSafety> IntoFuture for &'a Handler<T, TS>
Source§type IntoFuture = Waiter<'a, T, TS>
type IntoFuture = Waiter<'a, T, TS>
Which kind of future are we turning this into?
Source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Creates a future from a value. Read more
impl<T: Event, TS: ThreadSafety> Unpin for Handler<T, TS>
Auto Trait Implementations§
impl<T, TS> Freeze for Handler<T, TS>
impl<T, TS> RefUnwindSafe for Handler<T, TS>where
<TS as __ThreadSafety>::OnceLock<Box<<TS as __ThreadSafety>::Mutex<State<T>>>>: RefUnwindSafe,
impl<T, TS> Send for Handler<T, TS>
impl<T, TS> Sync for Handler<T, TS>
impl<T, TS> UnwindSafe for Handler<T, TS>where
<TS as __ThreadSafety>::OnceLock<Box<<TS as __ThreadSafety>::Mutex<State<T>>>>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more