Struct RuntimeInbox

Source
pub struct RuntimeInbox<A> { /* private fields */ }
Expand description

UI-thread consumer for a bounded runtime mailbox.

The receiver and target RuntimeHandle remain UI-local. Dropping the inbox closes all sender clones and drops buffered actions.

§Examples

use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::RuntimeInbox;
let (_sender, inbox) = RuntimeInbox::<()>::channel(NonZeroUsize::new(2).unwrap());
assert_eq!(inbox.stats().drained, 0);

Implementations§

Source§

impl<A> RuntimeInbox<A>

Provides the operations defined for RuntimeInbox<A>.

Source

pub fn channel(capacity: NonZeroUsize) -> (RuntimeSender<A>, Self)

Creates a bounded mailbox with exact nonzero message capacity.

No wake callback is initially installed; messages sent before late installation retain a pending wake requirement.

§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::{RuntimeHandle, RuntimeInbox};
let (sender, mut inbox) = RuntimeInbox::channel(NonZeroUsize::new(2).unwrap());
sender.dispatch(8).unwrap();
let runtime = RuntimeHandle::new();
assert_eq!(inbox.drain(&runtime).unwrap().dispatched_actions, 1);
assert_eq!(runtime.take_actions(), [8]);
Source

pub fn install_wake(&self, wake: Arc<dyn UiWake>) -> Result<(), UiWakeError>

Installs or replaces the host wake callback. Messages queued before this call cause the newly installed callback to run immediately.

Callback invocation is synchronous and outside the wake mutex. On error, the callback remains installed and the wake remains retryable.

§Errors

Returns the callback’s UiWakeError when delivering an already outstanding notification fails.

§Examples
use std::num::NonZeroUsize; use std::sync::Arc;
use ailloli_ui_runtime::app::{RuntimeInbox, UiWake, UiWakeError};
struct Wake; impl UiWake for Wake { fn wake(&self)->Result<(),UiWakeError>{Ok(())} }
let (_sender, inbox) = RuntimeInbox::<()>::channel(NonZeroUsize::new(1).unwrap());
assert!(inbox.install_wake(Arc::new(Wake)).is_ok());
Source

pub fn detach_wake(&self)

Detaches the current host callback while retaining any outstanding wake requirement for the next installed callback.

§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::RuntimeInbox;
let (_sender, inbox) = RuntimeInbox::<()>::channel(NonZeroUsize::new(1).unwrap());
inbox.detach_wake();
assert_eq!(inbox.stats().wake_calls, 0);
Source

pub fn stats(&self) -> RuntimeInboxStats

Returns a non-resetting shared instrumentation snapshot.

§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::RuntimeInbox;
let (_sender, inbox) = RuntimeInbox::<()>::channel(NonZeroUsize::new(1).unwrap());
assert_eq!(inbox.stats(), Default::default());
Source

pub fn drain( &mut self, runtime: &RuntimeHandle<A>, ) -> Result<RuntimeDrain, UiWakeError>

Applies at most RUNTIME_INBOX_DRAIN_BUDGET messages to the UI-local runtime. When work remains, another host wake is requested.

Actions preserve FIFO order. Redraw pending markers are cleared as their messages are applied. At the budget, one extra message is prefetched to set remaining; it stays counted in depth until the next drain.

§Errors

Returns a wake error only when a remainder needs another host signal. By then the first 256 messages have already been applied and their result is not returned, so hosts should treat this failure as requiring prompt retry/fatal recovery rather than repeat the messages.

§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::{RuntimeHandle, RuntimeInbox};
let (sender, mut inbox) = RuntimeInbox::channel(NonZeroUsize::new(2).unwrap());
sender.dispatch("one").unwrap(); sender.request_redraw().unwrap();
let runtime = RuntimeHandle::new();
let result = inbox.drain(&runtime).unwrap();
assert_eq!((result.drained_messages, result.dispatched_actions, result.redraw_all), (2, 1, true));

Trait Implementations§

Source§

impl<A> Debug for RuntimeInbox<A>

Implements the fmt::Debug contract for RuntimeInbox<A>.

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value for human-readable diagnostics.

Auto Trait Implementations§

§

impl<A> Freeze for RuntimeInbox<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for RuntimeInbox<A>
where A: RefUnwindSafe,

§

impl<A> Send for RuntimeInbox<A>
where A: Send,

§

impl<A> !Sync for RuntimeInbox<A>

§

impl<A> Unpin for RuntimeInbox<A>
where A: Unpin,

§

impl<A> UnwindSafe for RuntimeInbox<A>
where A: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> ErasedDestructor for T
where T: 'static,