Skip to main content

Binding

Struct Binding 

Source
pub struct Binding<T: 'static>(/* private fields */);
Expand description

A Binding<T> represents a mutable value of type T that can be observed.

Bindings provide a reactive way to work with values. When a binding’s value changes, it can notify watchers that have registered interest in the value.

Implementations§

Source§

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

Source

pub fn container(value: T) -> Self

Creates a new binding from a value by wrapping it in a container.

The container provides the reactive capabilities for the value.

Source§

impl<T: 'static> Binding<T>

Source

pub fn custom(custom: impl CustomBinding<Output = T> + Clone + 'static) -> Self

Creates a binding that uses a custom implementation of the CustomBinding trait.

Source

pub fn get_mut(&self) -> BindingMutGuard<'_, T>

Gets mutable access to the binding’s value through a guard.

When the guard is dropped, the binding is updated with the modified value.

Note: In rust, let _ = binding.get_mut(); DO NOT immediately drop the guard. Since it just binds to a variable named _, the guard will live until the end of the current scope. Please use *guard to modify the value in one line.

§Example
use nami::Binding;
let n = Binding::i32(10);
*n.get_mut() += 5; // do not bind the guard to a let pattern...even it is `_`

Tip: For better performance when modifying container bindings, consider using the with_mut method instead.

Source

pub fn set(&self, value: T)

Sets the binding to a new value

Source

pub fn take(&self) -> T
where T: Default + Clone,

Takes the value out of the binding, replacing it with the default value.

This is equivalent to std::mem::take and notifies watchers of the change.

§Example
use nami::{binding, Binding, Signal};
let mut text: Binding<String> = binding("hello");
let taken = text.take();
assert_eq!(taken, "hello");
assert_eq!(text.snapshot(), String::new());
Source

pub fn set_from(&self, value: impl Into<T>)

Sets the binding to a new value with automatic type conversion.

Accepts any value that implements Into<T>, providing the same ergonomic benefits as the binding() constructor.

§Examples
use nami::{binding, Binding, Signal};

let mut text: Binding<String> = binding("initial");

// Direct &str usage - no .into() or .to_string() needed
text.set_from("updated");
assert_eq!(text.snapshot(), "updated");

let mut count: Binding<i64> = binding(0);
count.set(42);
assert_eq!(count.snapshot(), 42i64);
Source

pub fn with_mut<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
where T: Clone,

Applies a function to mutably borrow the binding’s value.

This is more efficient than get_mut() for container bindings as it avoids unnecessary cloning. The function receives a mutable reference to the value and any changes will notify watchers when the function completes.

Source

pub fn mapping<Output, Getter, Setter>( source: &Self, getter: Getter, setter: Setter, ) -> Binding<Output>
where Getter: 'static + Clone + Fn(T) -> Output, Setter: 'static + Clone + Fn(&Self, Output),

Creates a bidirectional mapping between this binding and another type.

The getter transforms values from this binding’s type to the output type. The setter transforms values from the output type back to this binding’s type.

Source

pub fn filter(&self, filter: impl 'static + Clone + Fn(&T) -> bool) -> Self
where T: 'static,

Creates a binding that only allows values passing a filter function.

When attempting to set a value that doesn’t pass the filter, the operation is ignored.

Source

pub fn condition( &self, condition: impl 'static + Clone + Fn(&T) -> bool, ) -> Binding<bool>
where T: 'static,

Creates a binding that maps this binding’s value to a boolean condition.

The resulting binding is read-only and reflects whether the condition is met.

§Example
use nami::Signal;
let number = nami::binding(5i32);
let is_positive = number.condition(|&n: &i32| n > 0);
assert_eq!(is_positive.snapshot(), true);
Source

pub fn equal_to(&self, other: T) -> Binding<bool>
where T: Clone + PartialEq + 'static,

Creates a binding that tracks whether this binding’s value equals a specific value.

The resulting binding is read-only.

§Example
use nami::Signal;
let text = nami::binding("hello".to_string());
let is_hello = text.equal_to("hello".to_string());
assert_eq!(is_hello.snapshot(), true);
Source§

impl<T: 'static> Binding<T>

Source

pub fn mailbox_with_executor<E: LocalExecutor>( &self, executor: E, ) -> BindingMailbox<T>

Attaches this Binding to a mailbox using a provided executor.

Returns a BindingMailbox which can be cloned and used to send the binding to other tasks for mutation or observation.

Source

pub fn mailbox(&self) -> BindingMailbox<T>

Attaches this Binding to a mailbox using the default native executor.

Source§

impl<T: PartialOrd + 'static> Binding<T>

Source

pub fn range(&self, range: impl RangeBounds<T> + Clone + 'static) -> Self

Creates a binding that only allows values within a specified range.

Source

pub fn clamp(&self, range: impl RangeBounds<T> + Clone + 'static) -> Self
where T: Clone,

Creates a binding that clamps values to the specified range.

Values below the range minimum are clamped to the minimum. Values above the range maximum are clamped to the maximum.

Source§

impl<T: Signed> Binding<T>

Source

pub fn sign(&self) -> Binding<bool>

Creates a binding that tracks the sign of this binding’s value.

The resulting binding is true for positive values and false for negative values. Setting true makes the value positive, setting false makes it negative.

Tip: Zero is considered positive.

§Example
use nami::{Binding, Signal};
let number = Binding::i32(-10i32);
let sign = number.sign();
assert_eq!(sign.snapshot(), false);
Source§

impl Binding<u32>

Source

pub fn u32(value: u32) -> Self

Creates a new u32 binding with the given value.

§Example
use nami::Signal;
let counter = nami::Binding::u32(42);
assert_eq!(counter.snapshot(), 42);
Source§

impl Binding<u64>

Source

pub fn u64(value: u64) -> Self

Creates a new u64 binding with the given value.

§Example
use nami::Signal;
let counter = nami::Binding::u64(42);
assert_eq!(counter.snapshot(), 42);
Source§

impl Binding<usize>

Source

pub fn usize(value: usize) -> Self

Creates a new usize binding with the given value.

§Example
use nami::Signal;
let index = nami::Binding::usize(10);
assert_eq!(index.snapshot(), 10);
Source§

impl Binding<i32>

Source

pub fn i32(value: i32) -> Self

Creates a new i32 binding with the given value.

§Example
use nami::Signal;
let counter = nami::Binding::i32(42);
assert_eq!(counter.snapshot(), 42);
Source§

impl Binding<i64>

Source

pub fn i64(value: i64) -> Self

Creates a new i64 binding with the given value.

§Example
use nami::Signal;
let counter = nami::Binding::i64(42);
assert_eq!(counter.snapshot(), 42);
Source§

impl Binding<isize>

Source

pub fn isize(value: isize) -> Self

Create a new isize binding with the given value.

§Example
use nami::Signal;
let index = nami::Binding::isize(10);
assert_eq!(index.snapshot(), 10);
Source§

impl Binding<f32>

Source

pub fn f32(value: f32) -> Self

Creates a new f32 binding with the given value.

§Example
use nami::Signal;
let ratio = nami::Binding::f32(3.14);
assert_eq!(ratio.snapshot(), 3.14);
Source§

impl Binding<f64>

Source

pub fn f64(value: f64) -> Self

Creates a new f64 binding with the given value.

§Example
use nami::Signal;
let ratio = nami::Binding::f64(3.14);
assert_eq!(ratio.snapshot(), 3.14);
Source§

impl Binding<bool>

Source

pub fn bool(value: bool) -> Self

Creates a new bool binding with the given value.

§Example
use nami::Signal;
let flag = nami::Binding::bool(true);
assert_eq!(flag.snapshot(), true);
Source§

impl<T: Clone> Binding<T>

Source

pub fn append<Ele>(&self, ele: Ele)
where T: Extend<Ele>,

Appends an element to the binding’s value and notifies watchers.

The binding’s value must implement Extend for the element type.

§Example
use nami::Signal;
let mut text: nami::Binding<String> = nami::binding(String::from("Hello"));
text.append(" World");
assert_eq!(text.snapshot(), "Hello World");
Source§

impl<T: Add<Output = T> + Clone + 'static> Binding<T>

Source

pub fn add_assign(&self, other: T)

Applies the + operation to the binding’s current value and the provided value.

Source§

impl<T: Sub<Output = T> + Clone + 'static> Binding<T>

Source

pub fn sub_assign(&self, other: T)

Applies the - operation to the binding’s current value and the provided value.

Source§

impl<T: Mul<Output = T> + Clone + 'static> Binding<T>

Source

pub fn mul_assign(&self, other: T)

Applies the * operation to the binding’s current value and the provided value.

Source§

impl<T: Div<Output = T> + Clone + 'static> Binding<T>

Source

pub fn div_assign(&self, other: T)

Applies the / operation to the binding’s current value and the provided value.

Source§

impl<T: Rem<Output = T> + Clone + 'static> Binding<T>

Source

pub fn rem_assign(&self, other: T)

Applies the % operation to the binding’s current value and the provided value.

Source§

impl<T: BitAnd<Output = T> + Clone + 'static> Binding<T>

Source

pub fn bitand_assign(&self, other: T)

Applies the & operation to the binding’s current value and the provided value.

Source§

impl<T: BitOr<Output = T> + Clone + 'static> Binding<T>

Source

pub fn bitor_assign(&self, other: T)

Applies the | operation to the binding’s current value and the provided value.

Source§

impl<T: BitXor<Output = T> + Clone + 'static> Binding<T>

Source

pub fn bitxor_assign(&self, other: T)

Applies the ^ operation to the binding’s current value and the provided value.

Source§

impl<T: Shl<Output = T> + Clone + 'static> Binding<T>

Source

pub fn shl_assign(&self, other: T)

Applies the << operation to the binding’s current value and the provided value.

Source§

impl<T: Shr<Output = T> + Clone + 'static> Binding<T>

Source

pub fn shr_assign(&self, other: T)

Applies the >> operation to the binding’s current value and the provided value.

Source§

impl<T> Binding<Option<T>>

Source

pub fn unwrap_or_else( &self, default: impl 'static + Clone + Fn() -> T, ) -> Binding<T>
where T: Clone + 'static,

Creates a binding that unwraps the option or uses a default value from a closure.

When setting values on the returned binding, they are wrapped in Some.

§Example
use nami::Signal;
let maybe_text = nami::binding(None::<String>);
let text = maybe_text.unwrap_or_else(|| "default".to_string());
assert_eq!(text.snapshot(), "default");
Source

pub fn unwrap_or(&self, default: T) -> Binding<T>
where T: Clone + 'static,

Creates a binding that unwraps the option or uses a default value.

When setting values on the returned binding, they are wrapped in Some.

§Example
use nami::Signal;
let maybe_number = nami::binding(None::<i32>);
let number = maybe_number.unwrap_or(42);
assert_eq!(number.snapshot(), 42);
Source

pub fn unwrap_or_default(&self) -> Binding<T>
where T: Default + Clone + 'static,

Creates a binding that unwraps the option or uses the type’s default value.

When setting values on the returned binding, they are wrapped in Some.

§Example
use nami::Signal;
let maybe_vec = nami::binding(None::<Vec<i32>>);
let vec: nami::Binding<Vec<i32>> = maybe_vec.unwrap_or_default();
assert!(vec.snapshot().is_empty());
Source

pub fn some_equal_to(&self, equal: T) -> Binding<bool>
where T: Eq + Clone + 'static,

Creates a binding that tracks whether this option contains a specific value.

The resulting binding is true when this option contains Some(equal), and false when it contains Some(other_value) or None. Setting true on the result sets this binding to Some(equal). Setting false has no effect on the binding.

§Example
use nami::Signal;
let maybe_text = nami::binding(Some("hello".to_string()));
let is_hello = maybe_text.some_equal_to("hello".to_string());
assert_eq!(is_hello.snapshot(), true);
Source§

impl Binding<bool>

Source

pub fn toggle(&self)

Toggles the boolean value and notifies watchers.

True becomes false, false becomes true.

§Example
use nami::Signal;
let mut flag = nami::binding(false);
flag.toggle();
assert_eq!(flag.snapshot(), true);
Source

pub fn then<T>(&self, if_true: T) -> Binding<Option<T>>
where T: Clone + 'static,

Creates a conditional binding that returns Some(value) when true, None when false.

Setting Some(value) on the result sets this binding to true. Setting None sets this binding to false.

§Example
use nami::Signal;
let is_logged_in = nami::binding(true);
let username = is_logged_in.then("alice".to_string());
assert_eq!(username.snapshot(), Some("alice".to_string()));
Source

pub fn then_some<T>(&self, if_true: T) -> Binding<Option<T>>
where T: Clone + 'static,

Creates a conditional binding that returns Some(value) when true, None when false.

This is identical to then() but follows Rust’s Option::then_some() naming convention.

§Example
use nami::Signal;
let enabled = nami::binding(false);
let button_text = enabled.then_some("Click me!".to_string());
assert_eq!(button_text.snapshot(), None);
Source

pub fn bidirectional_select<T>(&self, if_true: T, if_false: T) -> Binding<T>
where T: Eq + Clone + 'static,

Creates a bidirectional binding that selects between two values based on this boolean.

Returns if_true when this binding is true, if_false when false. Setting the if_true value on the result sets this binding to true. Setting the if_false value sets this binding to false.

This is a two-way binding. For one-way selection (e.g., in animations), use SignalExt::select instead which doesn’t require T: Eq.

§Example
use nami::Signal;
let dark_mode = nami::binding(false);
let theme = dark_mode.bidirectional_select("dark".to_string(), "light".to_string());
assert_eq!(theme.snapshot(), "light");
Source

pub fn reverse(&self) -> Self

Creates a binding that returns the logical inverse of this boolean binding.

When this binding is true, the returned binding is false, and vice versa. Setting a value on the returned binding will set the inverse value on this binding.

§Example
use nami::Signal;
let enabled = nami::binding(true);
let disabled = enabled.reverse();
assert_eq!(disabled.snapshot(), false);
Source§

impl<T> Binding<T>
where T: Clone + Neg<Output = T> + 'static,

Source

pub fn negate(&self) -> Self

Creates a binding that produces the negated value of this binding.

Updating the derived binding will reflect the negated value back to the source.

Source§

impl<T: Project> Binding<T>

Source

pub fn project(&self) -> T::Projected

Projects this binding into its component parts.

This method uses the Project trait implementation to decompose the binding into separate reactive bindings for each component. Changes to any projected binding will be reflected in the original binding and vice versa.

§Examples
use nami::{Binding, binding, Signal};

let tuple_binding: Binding<(i32, i32, i32)> = binding((1, 2, 3));
let (mut a, mut b, c) = tuple_binding.project();

// Modify individual projections
a.set(10);
b.set(20);

// Original binding reflects changes
assert_eq!(tuple_binding.snapshot(), (10, 20, 3));

Trait Implementations§

Source§

impl<T, RHS> Add<RHS> for Binding<T>
where Self: Signal<Output = T>, RHS: Signal, T: Add<RHS::Output> + Clone + 'static, RHS::Output: Clone,

Source§

type Output = Map<Zip<Binding<T>, RHS>, fn((T, <RHS as Signal>::Output)) -> <T as Add<<RHS as Signal>::Output>>::Output, <T as Add<<RHS as Signal>::Output>>::Output>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: RHS) -> Self::Output

Performs the + operation. Read more
Source§

impl<T, RHS> BitAnd<RHS> for Binding<T>
where Self: Signal<Output = T>, RHS: Signal, T: BitAnd<RHS::Output> + Clone + 'static, RHS::Output: Clone,

Source§

type Output = Map<Zip<Binding<T>, RHS>, fn((T, <RHS as Signal>::Output)) -> <T as BitAnd<<RHS as Signal>::Output>>::Output, <T as BitAnd<<RHS as Signal>::Output>>::Output>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: RHS) -> Self::Output

Performs the & operation. Read more
Source§

impl<T, RHS> BitOr<RHS> for Binding<T>
where Self: Signal<Output = T>, RHS: Signal, T: BitOr<RHS::Output> + Clone + 'static, RHS::Output: Clone,

Source§

type Output = Map<Zip<Binding<T>, RHS>, fn((T, <RHS as Signal>::Output)) -> <T as BitOr<<RHS as Signal>::Output>>::Output, <T as BitOr<<RHS as Signal>::Output>>::Output>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: RHS) -> Self::Output

Performs the | operation. Read more
Source§

impl<T, RHS> BitXor<RHS> for Binding<T>
where Self: Signal<Output = T>, RHS: Signal, T: BitXor<RHS::Output> + Clone + 'static, RHS::Output: Clone,

Source§

type Output = Map<Zip<Binding<T>, RHS>, fn((T, <RHS as Signal>::Output)) -> <T as BitXor<<RHS as Signal>::Output>>::Output, <T as BitXor<<RHS as Signal>::Output>>::Output>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: RHS) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T> Clone for Binding<T>

Source§

fn clone(&self) -> Self

Creates a clone of this binding.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Binding<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

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

Source§

fn default() -> Self

Creates a binding with the default value for type T.

Source§

impl<T, RHS> Div<RHS> for Binding<T>
where Self: Signal<Output = T>, RHS: Signal, T: Div<RHS::Output> + Clone + 'static, RHS::Output: Clone,

Source§

type Output = Map<Zip<Binding<T>, RHS>, fn((T, <RHS as Signal>::Output)) -> <T as Div<<RHS as Signal>::Output>>::Output, <T as Div<<RHS as Signal>::Output>>::Output>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: RHS) -> Self::Output

Performs the / operation. Read more
Source§

impl<T> From<Binding<T>> for Computed<T>

Source§

fn from(val: Binding<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, RHS> Mul<RHS> for Binding<T>
where Self: Signal<Output = T>, RHS: Signal, T: Mul<RHS::Output> + Clone + 'static, RHS::Output: Clone,

Source§

type Output = Map<Zip<Binding<T>, RHS>, fn((T, <RHS as Signal>::Output)) -> <T as Mul<<RHS as Signal>::Output>>::Output, <T as Mul<<RHS as Signal>::Output>>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: RHS) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> Neg for Binding<T>
where T: Clone + Neg<Output = T> + 'static,

Source§

fn neg(self) -> Self::Output

Implements unary negation for bindings.

Source§

type Output = Binding<T>

The resulting type after applying the - operator.
Source§

impl Not for Binding<bool>

Source§

fn not(self) -> Self::Output

Implements the logical NOT operator for boolean bindings.

Source§

type Output = Binding<bool>

The resulting type after applying the ! operator.
Source§

impl<T, RHS> Rem<RHS> for Binding<T>
where Self: Signal<Output = T>, RHS: Signal, T: Rem<RHS::Output> + Clone + 'static, RHS::Output: Clone,

Source§

type Output = Map<Zip<Binding<T>, RHS>, fn((T, <RHS as Signal>::Output)) -> <T as Rem<<RHS as Signal>::Output>>::Output, <T as Rem<<RHS as Signal>::Output>>::Output>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: RHS) -> Self::Output

Performs the % operation. Read more
Source§

impl<T, RHS> Shl<RHS> for Binding<T>
where Self: Signal<Output = T>, RHS: Signal, T: Shl<RHS::Output> + Clone + 'static, RHS::Output: Clone,

Source§

type Output = Map<Zip<Binding<T>, RHS>, fn((T, <RHS as Signal>::Output)) -> <T as Shl<<RHS as Signal>::Output>>::Output, <T as Shl<<RHS as Signal>::Output>>::Output>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: RHS) -> Self::Output

Performs the << operation. Read more
Source§

impl<T, RHS> Shr<RHS> for Binding<T>
where Self: Signal<Output = T>, RHS: Signal, T: Shr<RHS::Output> + Clone + 'static, RHS::Output: Clone,

Source§

type Output = Map<Zip<Binding<T>, RHS>, fn((T, <RHS as Signal>::Output)) -> <T as Shr<<RHS as Signal>::Output>>::Output, <T as Shr<<RHS as Signal>::Output>>::Output>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: RHS) -> Self::Output

Performs the >> operation. Read more
Source§

impl<T: 'static> Signal for Binding<T>

Source§

fn snapshot(&self) -> Self::Output

Computes the current value of the binding.

Source§

fn with_ref<R>(&self, f: impl FnOnce(&T) -> R) -> R

Forwards to the erased binding. A Container-backed binding lends its value through a refcount bump on the shared Rc: mutating it inside f copies the value for the write and leaves f reading the old one, so it never panics.

Source§

fn watch( &self, watcher: impl Fn(Context<Self::Output>) + 'static, ) -> Self::Guard

Registers a watcher to be notified when the binding’s value changes.

Source§

type Output = T

The type of value produced by this computation.
Source§

type Guard = Box<dyn WatcherGuard>

The guard type returned by the watch method that manages watcher lifecycle.
Source§

fn identity(&self) -> Option<SignalIdentity>

Returns the stable semantic identity of this signal, when one exists. Read more
Source§

impl<T, RHS> Sub<RHS> for Binding<T>
where Self: Signal<Output = T>, RHS: Signal, T: Sub<RHS::Output> + Clone + 'static, RHS::Output: Clone,

Source§

type Output = Map<Zip<Binding<T>, RHS>, fn((T, <RHS as Signal>::Output)) -> <T as Sub<<RHS as Signal>::Output>>::Output, <T as Sub<<RHS as Signal>::Output>>::Output>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: RHS) -> Self::Output

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Binding<T>

§

impl<T> !Send for Binding<T>

§

impl<T> !Sync for Binding<T>

§

impl<T> !UnwindSafe for Binding<T>

§

impl<T> Freeze for Binding<T>
where Erased<T, BindingVtable<T>>: Freeze,

§

impl<T> Unpin for Binding<T>
where Erased<T, BindingVtable<T>>: Unpin,

§

impl<T> UnsafeUnpin for Binding<T>
where Erased<T, BindingVtable<T>>: UnsafeUnpin,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<C, F, T1, T2, Output> FlattenMap<F, (T1, T2), Output> for C
where C: Signal<Output = (T1, T2)> + 'static, F: 'static + Clone + Fn(T1, T2) -> Output, T1: 'static, T2: 'static, Output: 'static,

Source§

fn flatten_map(&self, f: F) -> Map<C, impl Clone + Fn((T1, T2)), Output>

Maps a function over the flattened elements of a nested tuple. Read more
Source§

impl<C, F, T1, T2, T3, Output> FlattenMap<F, (T1, T2, T3), Output> for C
where C: Signal<Output = ((T1, T2), T3)> + 'static, F: 'static + Clone + Fn(T1, T2, T3) -> Output, Output: 'static,

Source§

fn flatten_map(&self, f: F) -> Map<C, impl Clone + Fn(((T1, T2), T3)), Output>

Maps a function over the flattened elements of a nested tuple. 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 + Clone,

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<C, Output> IntoComputed<Output> for C
where Output: 'static, C: IntoSignal<Output> + 'static, <C as IntoSignal<Output>>::Signal: Clone + 'static,

Source§

fn into_computed(self) -> Computed<Output>

Convert this value into a Computed<Output>.

Source§

impl<C, Output> IntoSignal<Output> for C
where C: Signal, <C as Signal>::Output: 'static + Clone, Output: From<<C as Signal>::Output> + 'static,

Source§

fn into_signal(self) -> <C as IntoSignal<Output>>::Signal

Convert this computation into one that produces the desired output type.

Source§

type Signal = Map<C, fn(<C as Signal>::Output) -> Output, Output>

The specific computation type that will be produced.
Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

impl<C> SignalExt for C
where C: Signal,

Source§

fn map<F, Output>(&self, f: F) -> Map<Self, F, Output>
where F: 'static + Clone + Fn(Self::Output) -> Output, Output: 'static, Self: 'static,

Transforms the output of this signal using the provided function.
Source§

fn zip<B>(&self, b: &B) -> Zip<Self, B>
where B: Signal, Self::Output: Clone, B::Output: Clone,

Combines this signal with another signal into a tuple.
Source§

fn cached(&self) -> Cached<Self>
where Self::Output: Clone,

Wraps this signal with caching to avoid redundant computations.
Source§

fn computed(&self) -> Computed<Self::Output>
where Self: 'static,

Converts this signal into a type-erased Computed container.
Source§

fn with<T: 'static>(&self, metadata: T) -> WithMetadata<Self, T>

Attaches metadata to this signal’s watcher notifications.
Source§

fn map_into<U>(&self) -> Map<Self, fn(Self::Output) -> U, U>
where Self: 'static, Self::Output: Into<U>, U: 'static,

Transforms the output using Into::into.
Source§

fn inspect<F>( &self, f: F, ) -> Map<Self, impl 'static + Clone + Fn(Self::Output) -> Self::Output, Self::Output>
where Self: 'static, Self::Output: Clone + 'static, F: 'static + Clone + Fn(&Self::Output),

Applies a side-effect function and returns the original value.
Source§

fn distinct(&self) -> Distinct<Self>
where Self::Output: PartialEq + Clone,

Creates a distinct signal that only notifies on value changes.
Source§

fn equal_to( &self, other: Self::Output, ) -> Map<Self, impl 'static + Clone + Fn(Self::Output) -> bool, bool>
where Self: 'static, Self::Output: Clone + PartialEq + 'static,

Returns true if the value equals the given value. Read more
Source§

fn condition<F>( &self, predicate: F, ) -> Map<Self, impl 'static + Clone + Fn(Self::Output) -> bool, bool>
where Self: 'static, F: 'static + Clone + Fn(&Self::Output) -> bool,

Returns true if the predicate returns true for the value.
Source§

fn gt( &self, other: Self::Output, ) -> Map<Self, impl 'static + Clone + Fn(Self::Output) -> bool, bool>
where Self: 'static, Self::Output: Clone + PartialOrd + 'static,

Returns true if the value is greater than the given value.
Source§

fn lt( &self, other: Self::Output, ) -> Map<Self, impl 'static + Clone + Fn(Self::Output) -> bool, bool>
where Self: 'static, Self::Output: Clone + PartialOrd + 'static,

Returns true if the value is less than the given value.
Source§

fn ge( &self, other: Self::Output, ) -> Map<Self, impl 'static + Clone + Fn(Self::Output) -> bool, bool>
where Self: 'static, Self::Output: Clone + PartialOrd + 'static,

Returns true if the value is greater than or equal to the given value.
Source§

fn le( &self, other: Self::Output, ) -> Map<Self, impl 'static + Clone + Fn(Self::Output) -> bool, bool>
where Self: 'static, Self::Output: Clone + PartialOrd + 'static,

Returns true if the value is less than or equal to the given value.
Source§

fn is_some<T>(&self) -> Map<Self, fn(Option<T>) -> bool, bool>
where Self: Signal<Output = Option<T>> + 'static, T: 'static,

Returns true if the Option is Some.
Source§

fn is_none<T>(&self) -> Map<Self, fn(Option<T>) -> bool, bool>
where Self: Signal<Output = Option<T>> + 'static, T: 'static,

Returns true if the Option is None.
Source§

fn unwrap_or<T>( &self, default: T, ) -> Map<Self, impl 'static + Clone + Fn(Option<T>) -> T, T>
where Self: Signal<Output = Option<T>> + 'static, T: Clone + 'static,

Returns the contained value or a default.
Source§

fn unwrap_or_else<T, F>( &self, default: F, ) -> Map<Self, impl 'static + Clone + Fn(Option<T>) -> T, T>
where Self: Signal<Output = Option<T>> + 'static, T: 'static, F: 'static + Clone + Fn() -> T,

Returns the contained value or computes it from a closure.
Source§

fn unwrap_or_default<T>(&self) -> Map<Self, fn(Option<T>) -> T, T>
where Self: Signal<Output = Option<T>> + 'static, T: Default + 'static,

Returns the contained value or the default value for that type.
Source§

fn some_equal_to<T>( &self, value: T, ) -> Map<Self, impl 'static + Clone + Fn(Option<T>) -> bool, bool>
where Self: Signal<Output = Option<T>> + 'static, T: Clone + PartialEq + 'static,

Returns true if the Option is Some and the value equals the given value.
Source§

fn flatten<T>(&self) -> Map<Self, fn(Option<Option<T>>) -> Option<T>, Option<T>>
where Self: Signal<Output = Option<Option<T>>> + 'static, T: 'static,

Flattens a nested Option<Option<T>> into Option<T>.
Source§

fn map_some<T, U, F>( &self, f: F, ) -> Map<Self, impl 'static + Clone + Fn(Option<T>) -> Option<U>, Option<U>>
where Self: Signal<Output = Option<T>> + 'static, T: 'static, U: 'static, F: 'static + Clone + Fn(T) -> U,

Maps an Option<T> to Option<U> using the provided function.
Source§

fn and_then_some<T, U, F>( &self, f: F, ) -> Map<Self, impl 'static + Clone + Fn(Option<T>) -> Option<U>, Option<U>>
where Self: Signal<Output = Option<T>> + 'static, T: 'static, U: 'static, F: 'static + Clone + Fn(T) -> Option<U>,

Returns None if the option is None, otherwise calls f with the wrapped value and returns the result.
Source§

fn not(&self) -> Map<Self, fn(bool) -> bool, bool>
where Self: Signal<Output = bool> + 'static,

Returns the logical negation of the boolean value.
Source§

fn and<B>(&self, other: &B) -> Map<Zip<Self, B>, fn((bool, bool)) -> bool, bool>
where Self: Signal<Output = bool> + 'static, B: Signal<Output = bool> + 'static,

Returns the logical AND of this signal with another boolean signal.
Source§

fn or<B>(&self, other: &B) -> Map<Zip<Self, B>, fn((bool, bool)) -> bool, bool>
where Self: Signal<Output = bool> + 'static, B: Signal<Output = bool> + 'static,

Returns the logical OR of this signal with another boolean signal.
Source§

fn then_some<T>( &self, value: T, ) -> Map<Self, impl 'static + Clone + Fn(bool) -> Option<T>, Option<T>>
where Self: Signal<Output = bool> + 'static, T: Clone + 'static,

Returns Some(value) if true, otherwise None.
Source§

fn select<T>( &self, if_true: T, if_false: T, ) -> Map<Self, impl 'static + Clone + Fn(bool) -> T, T>
where Self: Signal<Output = bool> + 'static, T: Clone + 'static,

Returns if_true if true, otherwise if_false.
Source§

fn negate<T>(&self) -> Map<Self, fn(T) -> T, T>
where Self: Signal<Output = T> + 'static, T: Signed + 'static,

Returns the negation of the value.
Source§

fn abs<T>(&self) -> Map<Self, fn(T) -> T, T>
where Self: Signal<Output = T> + 'static, T: Signed + 'static,

Returns the absolute value.
Source§

fn sign<T>(&self) -> Map<Self, fn(T) -> bool, bool>
where Self: Signal<Output = T> + 'static, T: Signed + 'static,

Returns true if the value is not negative (i.e., positive or zero).
Source§

fn is_positive<T>(&self) -> Map<Self, fn(T) -> bool, bool>
where Self: Signal<Output = T> + 'static, T: Signed + 'static,

Returns true if the value is positive.
Source§

fn is_negative<T>(&self) -> Map<Self, fn(T) -> bool, bool>
where Self: Signal<Output = T> + 'static, T: Signed + 'static,

Returns true if the value is negative.
Source§

fn is_zero<T>(&self) -> Map<Self, fn(T) -> bool, bool>
where Self: Signal<Output = T> + 'static, T: Zero + 'static,

Returns true if the value is zero.
Source§

fn is_ok<T, E>(&self) -> Map<Self, fn(Result<T, E>) -> bool, bool>
where Self: Signal<Output = Result<T, E>> + 'static, T: 'static, E: 'static,

Returns true if the Result is Ok.
Source§

fn is_err<T, E>(&self) -> Map<Self, fn(Result<T, E>) -> bool, bool>
where Self: Signal<Output = Result<T, E>> + 'static, T: 'static, E: 'static,

Returns true if the Result is Err.
Source§

fn ok<T, E>(&self) -> Map<Self, fn(Result<T, E>) -> Option<T>, Option<T>>
where Self: Signal<Output = Result<T, E>> + 'static, T: 'static, E: 'static,

Converts from Result<T, E> to Option<T>.
Source§

fn err<T, E>(&self) -> Map<Self, fn(Result<T, E>) -> Option<E>, Option<E>>
where Self: Signal<Output = Result<T, E>> + 'static, T: 'static, E: 'static,

Converts from Result<T, E> to Option<E>.
Source§

fn unwrap_or_result<T, E>( &self, default: T, ) -> Map<Self, impl 'static + Clone + Fn(Result<T, E>) -> T, T>
where Self: Signal<Output = Result<T, E>> + 'static, T: Clone + 'static, E: 'static,

Returns the contained Ok value or a default.
Source§

fn unwrap_or_else_result<T, E, F>( &self, f: F, ) -> Map<Self, impl 'static + Clone + Fn(Result<T, E>) -> T, T>
where Self: Signal<Output = Result<T, E>> + 'static, T: 'static, E: 'static, F: 'static + Clone + Fn(E) -> T,

Returns the contained Ok value or computes it from the error.
Source§

fn map_ok<T, E, U, F>( &self, f: F, ) -> Map<Self, impl 'static + Clone + Fn(Result<T, E>) -> Result<U, E>, Result<U, E>>
where Self: Signal<Output = Result<T, E>> + 'static, T: 'static, E: 'static, U: 'static, F: 'static + Clone + Fn(T) -> U,

Maps a Result<T, E> to Result<U, E> using the provided function.
Source§

fn map_err<T, E, F, U>( &self, f: F, ) -> Map<Self, impl 'static + Clone + Fn(Result<T, E>) -> Result<T, U>, Result<T, U>>
where Self: Signal<Output = Result<T, E>> + 'static, T: 'static, E: 'static, U: 'static, F: 'static + Clone + Fn(E) -> U,

Maps a Result<T, E> to Result<T, F> using the provided function.
Source§

fn debounce(&self, duration: Duration) -> Debounce<Self, DefaultExecutor>
where Self::Output: Clone,

Creates a debounced version of this signal. Read more
Source§

fn throttle(&self, duration: Duration) -> Throttle<Self, DefaultExecutor>
where Self::Output: Clone,

Creates a throttled version of this signal. Read more
Source§

fn str_is_empty<T>(&self) -> Map<Self, fn(T) -> bool, bool>
where Self: Signal<Output = T> + 'static, T: AsRef<str> + 'static,

Returns true if the string is empty. Read more
Source§

fn str_len<T>(&self) -> Map<Self, fn(T) -> usize, usize>
where Self: Signal<Output = T> + 'static, T: AsRef<str> + 'static,

Returns the length of the string in bytes.
Source§

fn str_contains<T>( &self, pattern: impl Into<String>, ) -> Map<Self, impl 'static + Clone + Fn(T) -> bool, bool>
where Self: Signal<Output = T> + 'static, T: AsRef<str> + 'static,

Returns true if the string contains the given pattern. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.