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.
Sourcepub async fn get(&self) -> T
pub async fn get(&self) -> T
Gets the current value of the binding asynchronously via the mailbox.
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");Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more