Skip to main content

OneWayBinding

Struct OneWayBinding 

Source
pub struct OneWayBinding<T: Clone + 'static> { /* private fields */ }
Expand description

A one-way binding that pushes signal changes to a property sink.

When the source signal changes, the binding reads the new value and calls PropertySink::set_value on the sink.

§Examples

let count = Signal::new(0);
let display = Rc::new(RefCell::new(String::new()));

let binding = OneWayBinding::new(&count, {
    let display = display.clone();
    move |v: &i32| *display.borrow_mut() = format!("{v}")
});

count.set(42);
assert_eq!(*display.borrow(), "42");

Implementations§

Source§

impl<T: Clone + 'static> OneWayBinding<T>

Source

pub fn new(source: &Signal<T>, sink: impl PropertySink<T> + 'static) -> Self

Create a new one-way binding from source to sink.

The sink is called immediately with the current value, and again whenever the source signal changes.

Trait Implementations§

Source§

impl<T: Clone + 'static> Binding for OneWayBinding<T>

Source§

fn id(&self) -> BindingId

Unique identifier for this binding.
Source§

fn direction(&self) -> BindingDirection

Direction of data flow.
Source§

fn is_active(&self) -> bool

Whether this binding is still active.
Source§

fn dispose(&self)

Permanently deactivate this binding.

Auto Trait Implementations§

§

impl<T> Freeze for OneWayBinding<T>

§

impl<T> !RefUnwindSafe for OneWayBinding<T>

§

impl<T> !Send for OneWayBinding<T>

§

impl<T> !Sync for OneWayBinding<T>

§

impl<T> Unpin for OneWayBinding<T>

§

impl<T> !UnwindSafe for OneWayBinding<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, 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.