Skip to main content

RuntimeHandle

Struct RuntimeHandle 

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

A cheap handle to a Runtime. It does not keep the runtime alive, and its calls do nothing once the runtime is dropped.

Implementations§

Source§

impl RuntimeHandle

Source

pub fn id(&self) -> RuntimeId

Returns the id of the runtime.

Source

pub fn state_arena_stats(&self) -> (usize, usize)

Returns the number of state cells and, of those, the number free for reuse.

Source

pub fn state_arena_debug_stats(&self) -> StateArenaDebugStats

Returns the sizes of the runtime’s state arena, for leak and memory checks.

Source

pub fn debug_stats(&self) -> RuntimeDebugStats

Returns the sizes of the runtime’s queues and tables, for leak and memory checks.

Source

pub fn live_ui_task_labels(&self) -> Vec<(u64, String)>

Returns the id and label of every spawned UI task that has not finished.

Source

pub fn schedule(&self)

Marks the runtime as needing a frame and asks its scheduler for one.

Source

pub fn enqueue_ui_task(&self, task: Box<dyn FnOnce() + 'static>)

Schedules work that must run on the runtime thread.

The closure executes on the UI thread immediately when the runtime drains its local queue, so it may capture Rc/RefCell values. Calling this from any other thread is a logic error and will panic in debug builds via the inner assertion.

Source

pub fn spawn_ui<F>(&self, fut: F) -> Option<TaskHandle>
where F: Future<Output = ()> + 'static,

Spawns fut on the UI thread, where drain_ui polls it whenever it is woken. Returns None if the runtime is gone.

Source

pub fn cancel_task(&self, id: u64)

Cancels the spawned UI task id and drops its future.

Source

pub fn has_task(&self, id: u64) -> bool

Whether the runtime still holds the spawned task id.

Source

pub fn post_ui(&self, task: impl FnOnce() + Send + 'static)

Enqueues work from any thread to run on the UI thread.

The closure must be Send because it may cross threads before executing on the runtime thread. Use this when posting from background work.

Source

pub fn register_ui_cont<T: 'static>( &self, f: impl FnOnce(T) + 'static, ) -> Option<u64>

Registers f to run once on the UI thread when UiDispatcher::post_invoke sends a T for the returned id. Returns None if the runtime is gone.

Source

pub fn cancel_ui_cont(&self, id: u64)

Removes the continuation id without running it.

Source

pub fn drain_ui(&self)

Runs the work posted to the UI thread, including woken tasks, until none is left.

Source

pub fn has_pending_ui(&self) -> bool

Returns true if posted UI work has not run yet.

Source

pub fn register_frame_callback( &self, callback: impl FnOnce(u64) + 'static, ) -> Option<u64>

Registers callback to run once on the next frame with the frame time in nanoseconds. Returns None if the runtime is gone.

Source

pub fn register_perpetual_frame_callback( &self, callback: impl FnOnce(u64) + 'static, ) -> Option<u64>

Registers callback to run once on the next frame, for a long-lived loop that registers again after every frame. It does not count in has_transient_frame_callbacks.

Source

pub fn cancel_frame_callback(&self, id: u64)

Cancels the frame callback id if it has not run.

Source

pub fn drain_frame_callbacks(&self, frame_time_nanos: u64)

Delivers callbacks registered before this display frame. Timestamps use one monotonic nanosecond epoch; duplicate or older timestamps are ignored. A callback registered during delivery waits for a newer frame timestamp.

Source

pub fn last_frame_time_nanos(&self) -> Option<u64>

Animation-clock time of the most recent frame-callback drain (see Runtime::last_frame_time_nanos).

Source

pub fn frame_clock(&self) -> FrameClock

Returns a clock for the frames of this runtime.

Source

pub fn set_needs_frame(&self, value: bool)

Sets or clears the request for a frame.

Source

pub fn has_updates(&self) -> bool

Returns true if node updates are queued or any recompose scope is invalid.

Source

pub fn forget_movable(&self, id: Key)

Releases the retained state of the movable content with identity id at the composition’s next opportunity. See crate::forget_movable.

Source

pub fn has_invalid_scopes(&self) -> bool

Returns true if a recompose scope has been invalidated and not yet recomposed.

Source

pub fn has_frame_callbacks(&self) -> bool

Returns true if any frame callback, transient or perpetual, is waiting.

Source

pub fn has_transient_frame_callbacks(&self) -> bool

Returns true if a callback from register_frame_callback is waiting. Perpetual callbacks do not count.

Source

pub fn assert_ui_thread(&self)

Panics in debug builds when called off the runtime’s UI thread.

Source

pub fn dispatcher(&self) -> UiDispatcher

Returns a dispatcher that posts work to the UI thread from any thread.

Trait Implementations§

Source§

impl Clone for RuntimeHandle

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.