pub struct EventReceiver(/* private fields */);
Expand description
Handle for receiving events from the main event loop.
Unlike a raw std::sync::mpsc::Receiver
, this never returns error on
disconnection, because disconnection can only occur for a brief moment
between the main event loop beginning to shut down, and the process as a
whole exiting. Therefore, when this receives a disconnection error from
the underlying receiver, it enters an infinite sleep cycle as it waits for
the OS to kill the process.
Implementations§
Source§impl EventReceiver
impl EventReceiver
Sourcepub fn recv(&self) -> Event<'static, Blocker>
pub fn recv(&self) -> Event<'static, Blocker>
Receive an event, blocking until one is available.
Sourcepub fn recv_timeout(&self, timeout: Duration) -> Option<Event<'static, Blocker>>
pub fn recv_timeout(&self, timeout: Duration) -> Option<Event<'static, Blocker>>
Attempt to receive an event, blocking until one is available, or the
timeout
duration has passed.
Sourcepub fn try_recv(&self) -> Option<Event<'static, Blocker>>
pub fn try_recv(&self) -> Option<Event<'static, Blocker>>
Try to receive an event immediately, never blocking.
Sourcepub fn iter<'a>(&'a self) -> impl Iterator<Item = Event<'static, Blocker>> + 'a
pub fn iter<'a>(&'a self) -> impl Iterator<Item = Event<'static, Blocker>> + 'a
Iterator form of self.recv()
. Blocking iterator that never ends.
Examples found in repository?
examples/winit_readme.rs (line 41)
35fn main() {
36 winit_main::run(|event_loop, events| {
37 let window = event_loop
38 .create_window(WindowAttributes::default())
39 .unwrap();
40
41 for event in events.iter() {
42 if matches!(
43 event,
44 Event::WindowEvent {
45 event: WindowEvent::CloseRequested,
46 window_id,
47 } if window_id == window.id()
48 ) {
49 break;
50 }
51 }
52 });
53}
Auto Trait Implementations§
impl Freeze for EventReceiver
impl RefUnwindSafe for EventReceiver
impl Send for EventReceiver
impl !Sync for EventReceiver
impl Unpin for EventReceiver
impl UnwindSafe for EventReceiver
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