Struct MessageLoop

Source
pub struct MessageLoop { /* private fields */ }
Expand description

Abstract representation of a message loop.

Not directly constructible, use MessageLoop::run to create a message loop. The message loop struct is used to control the message loop behavior by passing it as an argument to the filter closure of MessageLoop::run.

Implementations§

Source§

impl MessageLoop

Source

pub fn run(filter: impl Fn(&MessageLoop, &MSG) -> FilterResult)

Runs the message loop with a filter closure to inspect and drop messages before they are dispatched to their respective window procedure.

Use the FilterResult return value to control how the message is handled. The first argument to the filter closure is the MessageLoop struct itself, which can be used to quit out of the message loop.

Like block_on this function runs any tasks [spawn]ed from the same thread. Any spawned tasks will be suspended when the run_message_loop returns. Be careful not to drop messages not belonging to a window you control or you might risk suspending a task indefinitely when dropping its wake message.

run_message_loop installs a WH_MSGFILTER hook to allow inspections of messages while modal windows are open.

§Panics and Reentrancy

Panics when called from within another run_message_loop filter closure. A call to block_on() from within the filter closure creates a nested message loop which causes the filter closure to be reentered when a modal window is open.

Source

pub fn quit(&self)

Quits the message loop as soon as possible.

Source

pub fn quit_when_idle(&self)

Quits the message loop when there are no more messages to process.

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.