pub struct EventProxy<T: Send + 'static = u64>(/* private fields */);Expand description
A thread-safe handle for injecting application-defined events into a running windowed event loop from another thread (network, audio, timer, …).
Obtained via the on_proxy callback passed to run_windowed_with_proxy/
run_app_with_proxy (payload fixed to u64, delivered as Event::Custom) or
run_windowed_with_typed_proxy/run_app_with_typed_proxy (any T: Send + 'static,
delivered to a caller-supplied handler), invoked synchronously right after the event loop
(and this proxy) is created, before the loop starts blocking the calling thread. Clone it
freely to hand a copy to each worker thread that needs to wake the loop; wraps winit’s own
EventLoopProxy, which is Send + Sync for any
T: Send + 'static payload.
T defaults to u64 (the payload Event::Custom itself carries), so existing code
naming the bare EventProxy type (from before this type became generic) keeps compiling
unchanged.
Implementations§
Source§impl<T: Send + 'static> EventProxy<T>
impl<T: Send + 'static> EventProxy<T>
Sourcepub fn send_event(&self, payload: T) -> Result<(), EventProxyClosed<T>>
pub fn send_event(&self, payload: T) -> Result<(), EventProxyClosed<T>>
Injects payload into the event loop’s queue, waking it if it’s asleep.
With the default T = u64 (via run_windowed_with_proxy/run_app_with_proxy), the
payload surfaces through the app’s normal poll_event/frame loop as
Event::Custom(payload), like any other Event. With a custom T
(via run_windowed_with_typed_proxy/run_app_with_typed_proxy), the payload is
handed directly to that call’s on_custom_event handler instead: it never becomes an
Event, since Event::Custom is fixed to u64.
§Errors
Returns EventProxyClosed if the event loop has already exited.
Trait Implementations§
Source§impl<T: Send + 'static> Clone for EventProxy<T>
impl<T: Send + 'static> Clone for EventProxy<T>
Auto Trait Implementations§
impl<T> Freeze for EventProxy<T>
impl<T> RefUnwindSafe for EventProxy<T>
impl<T> Send for EventProxy<T>
impl<T> Sync for EventProxy<T>
impl<T> Unpin for EventProxy<T>
impl<T> UnsafeUnpin for EventProxy<T>
impl<T> UnwindSafe for EventProxy<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.