Struct UiInbox

Source
pub struct UiInbox<T> { /* private fields */ }
Expand description

UI-thread side of a bounded generic mailbox.

Receiver is single-consumer and this type is intended to stay on the UI thread. Dropping it closes the channel after buffered messages are dropped.

§Examples

use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::UiInbox;
let (_sender, inbox) = UiInbox::<u8>::channel(NonZeroUsize::new(4).unwrap());
assert_eq!(inbox.stats().current_depth, 0);

Implementations§

Source§

impl<T> UiInbox<T>

Provides the operations defined for UiInbox<T>.

Source

pub fn channel(capacity: NonZeroUsize) -> (UiSender<T>, Self)

Creates a bounded channel with exact nonzero message capacity.

No wake callback is installed. Producers may enqueue before late wake installation; the outstanding notification is retained.

§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::UiInbox;
let (sender, mut inbox) = UiInbox::channel(NonZeroUsize::new(2).unwrap());
sender.send(5).unwrap();
assert_eq!(inbox.drain(NonZeroUsize::new(2).unwrap()).unwrap().messages, [5]);
Source

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

Installs/replaces the thread-safe host wake callback.

If a wake is outstanding, the new callback is invoked synchronously before this method returns. Its error is returned; the callback remains installed and notification stays retryable.

§Errors

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

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

pub fn detach_wake(&self)

Removes the current callback without discarding an outstanding wake.

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

pub fn stats(&self) -> UiInboxStats

Returns a non-resetting shared statistics snapshot.

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

pub fn drain(&mut self, limit: NonZeroUsize) -> Result<UiDrain<T>, UiWakeError>

Removes up to limit FIFO messages and reports whether more remain.

When exactly limit messages were removed, the method probes one extra message and retains it internally to determine remaining. If work remains it synchronously requests another wake. A wake error is returned after the batch has already been removed and counters updated, so the caller does not receive those messages and must treat such a failure as host-fatal or arrange higher-level recovery.

§Errors

Returns a wake error only when a pending remainder needs another signal. Channel disconnection is recorded in stats and otherwise yields a normal drain result.

§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::UiInbox;
let (sender, mut inbox) = UiInbox::channel(NonZeroUsize::new(3).unwrap());
sender.send(1).unwrap(); sender.send(2).unwrap();
let first = inbox.drain(NonZeroUsize::new(1).unwrap()).unwrap();
assert_eq!(first.messages, [1]);
assert!(first.remaining);

Auto Trait Implementations§

§

impl<T> Freeze for UiInbox<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for UiInbox<T>
where T: RefUnwindSafe,

§

impl<T> Send for UiInbox<T>
where T: Send,

§

impl<T> !Sync for UiInbox<T>

§

impl<T> Unpin for UiInbox<T>
where T: Unpin,

§

impl<T> UnwindSafe for UiInbox<T>
where T: 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,