Skip to main content

PumpRunner

Struct PumpRunner 

Source
pub struct PumpRunner<A: App> { /* private fields */ }
Expand description

A windowed runner driven from outside, from Launcher::open: the same runner as Launcher::run (input mapping, IME, clipboard, chrome, caret blink), but the host calls pump or pump_until on its own cadence instead of parking in the event loop.

Ask next_deadline after each pump for how long to sleep, and request_redraw after changing what view will produce. The runner ends when the main window closes; dropping it earlier closes the windows and parks the loop for the next open.

Implementations§

Source§

impl<A: App> PumpRunner<A>

Source

pub fn pump(&mut self) -> bool

Processes all pending OS events without blocking. Returns false once the main window has closed — and from that pump on the windows are gone and the loop is parked for the next runner; further pumps are no-ops.

Source

pub fn pumps(&self) -> u64

How many turns this runner has taken, the one that opened the window included: every pump and pump_until that ran, not the no-ops after it retired. Monotonic, so two readings a second apart give the pump rate over that second. How many of them something outside the app caused is woken_pumps.

Source

pub fn woken_pumps(&self) -> u64

How many of those pumps found an OS event or a wake in their batch: any window event but a redraw (a key, the pointer crossing the window, a focus change, a resize, the window moved or occluded), or anything that came through the loop’s proxy (a Waker::wake, assistive technology asking, a file dialog’s answer). Monotonic, and never more than pumps.

Unmoved over a second, the desktop left the window alone and whatever it drew was the app’s own doing; moved, the desktop or a person reached in, so an idle-window measurement should restart rather than fail.

Source

pub fn pump_until(&mut self, deadline: Instant) -> bool

pump, but parked until an OS event, a Waker::wake or deadline, whichever comes first, so a host that owns the loop blocks on all three instead of polling on a timer. Returns false once the main window has closed.

Source

pub fn next_deadline(&self) -> Option<Instant>

When the runner next needs pumping, as the last pump left it: a caret blink, a tick, a transition’s next frame, the audio poll or a first-frame retry. None when nothing it knows about is due. Ask after each pump and sleep until the answer rather than pumping on a fixed interval.

It does not say whether an OS event is waiting, since nothing short of pumping can, so a driver still needs a ceiling of its own; this only ever says to come back sooner.

Source

pub fn waker(&self) -> Waker

A Waker for this loop, to clone into the threads the host’s data arrives on.

Source

pub fn app_mut(&mut self) -> &mut A

The app, for a host that reads or changes its state between pumps.

Source

pub fn route_events( &mut self, events: impl IntoIterator<Item = UiEvent>, to_app: impl FnMut(&mut A, UiEvent, &mut Core), )

Delivers events the way this runner’s own loop does: an extension’s event to the extension, and the rest, with whatever the extension replied, to to_app. Use it for events the loop never saw, such as those a host produced by driving the core directly (core_mut().press, an access action, a drained take_pending_events); pushing those straight at the app would hand it an extension’s clicks and leave the extension deaf to them.

to_app is lent the core of the window each event came from, as App::on_event_with is.

Source

pub fn core_mut(&mut self) -> &mut Core

The main window’s core. Every window of the app shares its session, so resources registered through it draw in all of them, and Core::windows on it lists them.

Source

pub fn core_mut_of(&mut self, id: WindowId) -> Option<&mut Core>

The core of the window id names, if that window is open; the main window’s for WindowId::MAIN. Everything that is one window’s rather than the session’s (its focus, its editors’ text, its scroll offsets, its tokens) is answered by this core and no other.

Source

pub fn window_id(&mut self, name: &str) -> Option<WindowId>

The id of the open window named name ("main" for the launcher’s), or None while no window of that name is open — before its first frame’s diff, or after the user closed it.

Source

pub fn window_size(&self) -> (Size, f32)

The main window’s inner size (logical px) and its scale factor. Unlike core_mut().viewport() this is known before the first frame, so a host can size its model at setup. core_mut().host_area(size) is what the next frame lays out against: the window less the devtools’ dock while the panel is docked, the window otherwise.

Source

pub fn request_redraw(&self)

Schedules a redraw of every window; call it after changing what view will produce. Under Launcher::deferred_events it also ends a frame’s wait: the host is saying its view is current, so the waiting frame is painted with the answer in it.

Source

pub fn request_exit(&mut self)

Asks the app to close; the next pump observes it and returns false.

Source

pub fn flush_audio(&mut self)

Hands the core’s queued audio commands to the device now rather than at the next pump, for a host that calls Core::play between pumps and wants the sound to start at once.

Trait Implementations§

Source§

impl<A: App> Drop for PumpRunner<A>

Source§

fn drop(&mut self)

A runner dropped while alive — a host that let go of it without pumping to the end — parks the loop too, so the next open on the thread is not refused for its sake.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<A> !Freeze for PumpRunner<A>

§

impl<A> !RefUnwindSafe for PumpRunner<A>

§

impl<A> !Send for PumpRunner<A>

§

impl<A> !Sync for PumpRunner<A>

§

impl<A> !UnwindSafe for PumpRunner<A>

§

impl<A> Unpin for PumpRunner<A>
where ManuallyDrop<Box<Shell<A>>>: Unpin,

§

impl<A> UnsafeUnpin for PumpRunner<A>
where ManuallyDrop<Box<Shell<A>>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more