BindingMailbox

Struct BindingMailbox 

Source
pub struct BindingMailbox<T>
where T: 'static,
{ /* private fields */ }
Expand description

A handle for interacting with a background mailbox tied to a Binding.

Implementations§

Source§

impl<T> BindingMailbox<T>
where T: 'static,

Source

pub fn handle(&self, job: impl FnOnce(&mut Binding<T>) + Send + 'static)

Sends a job to be executed with the binding on the background task.

The job will be executed asynchronously and will have access to the binding for reading or modifying its value.

Source

pub async fn get(&self) -> T
where T: Clone + Send,

Gets the current value of the binding asynchronously via the mailbox.

Source

pub async fn get_as<T2>(&self) -> T2
where T2: Send + 'static + From<T>,

Gets the current value of the binding asynchronously and converts it to type T2.

This method retrieves the binding’s value via the mailbox and automatically converts it to the target type using the From trait. This is particularly useful for bindings with non-Send types (like waterui_str::Str) that need to be converted to Send types (like String) for use across async boundaries.

§Type Parameters
  • T2 - The target type to convert to. Must implement From<T> where T is the binding’s value type.
§Examples
// Convert Str binding to String for cross-thread usage  
use nami::{binding, Binding};
use waterui_str::Str;
let text_binding:Binding<Str> = nami::binding("hello world");
let mailbox = text_binding.mailbox();
let owned_string: String = mailbox.get_as().await;
assert_eq!(owned_string, "hello world");
Source

pub async fn set(&self, value: impl Into<T> + Send + 'static)

Sets a new value on the binding asynchronously via the mailbox.

Trait Implementations§

Source§

impl<T> Debug for BindingMailbox<T>
where T: Debug + 'static,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for BindingMailbox<T>

§

impl<T> RefUnwindSafe for BindingMailbox<T>

§

impl<T> Send for BindingMailbox<T>

§

impl<T> Sync for BindingMailbox<T>

§

impl<T> Unpin for BindingMailbox<T>

§

impl<T> UnwindSafe for BindingMailbox<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> IdentifiableExt for T

Source§

fn use_id<F, Id>(self, f: F) -> UseId<Self, F>
where F: Fn(&Self) -> Id, Id: Ord + Hash,

Wraps the value in a UseId with the provided identification function.
Source§

fn self_id(self) -> SelfId<Self>

Wraps the value in a SelfId, making the value serve as its own identifier.
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, 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.