Struct UiSender

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

Thread-safe producer for a bounded, wakeable UI mailbox.

Clones share the same channel and counters. UiSender<T> is Send + Sync when T permits it; ordering follows the standard MPSC channel across all producers.

§Examples

use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::UiInbox;
let (sender, _inbox) = UiInbox::<u8>::channel(NonZeroUsize::new(2).unwrap());
assert_eq!(sender.stats().enqueued, 0);

Implementations§

Source§

impl<T> UiSender<T>

Provides the operations defined for UiSender<T>.

Source

pub fn send(&self, message: T) -> Result<(), UiSendError>

Attempts a nonblocking enqueue, then coalesces a host wake.

On Full or Closed, ownership of message is lost with the error and the queue is unchanged. EnqueuedButWakeFailed means the message remains queued. With no callback installed, the send succeeds and records a wake requirement for late installation.

§Errors

Returns UiSendError::Full or UiSendError::Closed without enqueueing. UiSendError::EnqueuedButWakeFailed means enqueueing succeeded but the installed wake callback failed.

§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::{UiInbox, UiSendError};
let (sender, _inbox) = UiInbox::channel(NonZeroUsize::new(1).unwrap());
sender.send(1).unwrap();
assert_eq!(sender.send(2), Err(UiSendError::Full));
Source

pub fn send_blocking(&self, message: T) -> Result<(), UiSendError>

Enqueues with bounded backpressure, then wakes the UI host.

Worker threads may use this when dropping a response would violate their protocol. UI threads should prefer Self::send so they never block on a full mailbox.

This can block indefinitely while the receiver remains alive but does not drain a full queue. A wake failure still leaves the message queued.

§Errors

Returns UiSendError::Closed if the receiver disappears before the enqueue, or UiSendError::EnqueuedButWakeFailed after a successful enqueue whose host wake failed.

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

pub fn request_wake(&self) -> Result<(), UiSendError>

Retries an outstanding wake without adding another message.

A signaled/in-flight wake coalesces to success. With no callback this records NeedsWake and also returns success.

§Errors

Returns UiSendError::EnqueuedButWakeFailed when the installed wake callback reports a closed or temporarily unavailable target.

§Examples
use std::num::NonZeroUsize;
use ailloli_ui_runtime::app::UiInbox;
let (sender, _inbox) = UiInbox::<()>::channel(NonZeroUsize::new(1).unwrap());
assert!(sender.request_wake().is_ok());
assert_eq!(sender.stats().enqueued, 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());
sender.send(1).unwrap();
assert_eq!(sender.stats().current_depth, 1);

Trait Implementations§

Source§

impl<T> Clone for UiSender<T>

Implements the Clone contract for UiSender<T>.

Source§

fn clone(&self) -> Self

Produces the clone required by the standard cloning contract.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for UiSender<T>

Implements the fmt::Debug contract for UiSender<T>.

Source§

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

Formats the value for human-readable diagnostics.

Auto Trait Implementations§

§

impl<T> Freeze for UiSender<T>

§

impl<T> RefUnwindSafe for UiSender<T>

§

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

§

impl<T> Sync for UiSender<T>
where T: Send,

§

impl<T> Unpin for UiSender<T>

§

impl<T> UnwindSafe for UiSender<T>

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<A> IntoClickAction<A> for A
where A: Clone + 'static,

Source§

fn into_click_action(self) -> ClickAction<A>

Implements the into_click_action helper used by this module.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = 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,

Source§

impl<T> Props for T
where T: Clone + 'static,