pub struct BindingScope { /* private fields */ }Expand description
A scope that owns bindings and disposes them on drop.
BindingScope provides a convenient way to manage the lifetime
of multiple bindings. When the scope is dropped, all owned bindings
are disposed.
§Examples
ⓘ
let count = Signal::new(0);
let display = Rc::new(RefCell::new(String::new()));
{
let mut scope = BindingScope::new();
scope.bind(&count, {
let display = display.clone();
move |v: &i32| *display.borrow_mut() = format!("{v}")
});
count.set(5);
assert_eq!(*display.borrow(), "5");
}
// Scope dropped — binding disposed.
count.set(99);
// display still shows "5" because the binding is gone.Implementations§
Source§impl BindingScope
impl BindingScope
Sourcepub fn bind<T: Clone + 'static>(
&mut self,
source: &Signal<T>,
sink: impl PropertySink<T> + 'static,
) -> BindingId
pub fn bind<T: Clone + 'static>( &mut self, source: &Signal<T>, sink: impl PropertySink<T> + 'static, ) -> BindingId
Create a one-way binding from source to sink.
Returns the binding ID.
Sourcepub fn bind_two_way<T: Clone + 'static>(
&mut self,
source: &Signal<T>,
sink: impl PropertySink<T> + 'static,
) -> (TwoWayBinding<T>, BindingId)
pub fn bind_two_way<T: Clone + 'static>( &mut self, source: &Signal<T>, sink: impl PropertySink<T> + 'static, ) -> (TwoWayBinding<T>, BindingId)
Create a two-way binding between source and sink.
Returns the TwoWayBinding (for calling write_back) and the binding ID.
Sourcepub fn bind_expression<S: Clone + 'static, T: Clone + 'static>(
&mut self,
source: &Signal<S>,
transform: impl Fn(&S) -> T + 'static,
sink: impl PropertySink<T> + 'static,
) -> BindingId
pub fn bind_expression<S: Clone + 'static, T: Clone + 'static>( &mut self, source: &Signal<S>, transform: impl Fn(&S) -> T + 'static, sink: impl PropertySink<T> + 'static, ) -> BindingId
Create a binding expression (source → transform → sink).
Returns the binding ID.
Sourcepub fn binding_count(&self) -> usize
pub fn binding_count(&self) -> usize
Get the number of bindings in this scope.
Sourcepub fn is_binding_active(&self, id: BindingId) -> bool
pub fn is_binding_active(&self, id: BindingId) -> bool
Check if a specific binding is still active.
Trait Implementations§
Source§impl Default for BindingScope
impl Default for BindingScope
Auto Trait Implementations§
impl Freeze for BindingScope
impl !RefUnwindSafe for BindingScope
impl !Send for BindingScope
impl !Sync for BindingScope
impl Unpin for BindingScope
impl !UnwindSafe for BindingScope
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