Struct EventReceiver

Source
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

Source

pub fn recv(&self) -> Event<'static, Blocker>

Receive an event, blocking until one is available.

Source

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.

Source

pub fn try_recv(&self) -> Option<Event<'static, Blocker>>

Try to receive an event immediately, never blocking.

Source

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}
Source

pub fn try_iter<'a>( &'a self, ) -> impl Iterator<Item = Event<'static, Blocker>> + 'a

Iterator form of self.try_recv(). Non-blocking iterator that drains the events currently in the queue.

Auto Trait Implementations§

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