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,
impl<T> BindingMailbox<T>where
T: 'static,
Sourcepub fn handle(&self, job: impl FnOnce(&mut Binding<T>) + Send + 'static)
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.
§Panics
Panics when the mailbox receiver is closed and the job cannot be enqueued.
Sourcepub async fn get(&self) -> T
pub async fn get(&self) -> T
Gets the current value of the binding asynchronously via the mailbox.
§Panics
Panics when the value request cannot be sent to the mailbox worker or when the response channel is unexpectedly closed.
Sourcepub async fn get_as<T2>(&self) -> T2
pub async fn get_as<T2>(&self) -> T2
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 implementFrom<T>whereTis 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");§Panics
Panics when the value request cannot be sent to the mailbox worker or when the response channel is unexpectedly closed.