Struct SignalSetter

Source
pub struct SignalSetter<T, S = SyncStorage>
where T: 'static,
{ /* private fields */ }
Expand description

A wrapper for any kind of settable reactive signal: a WriteSignal, RwSignal, or closure that receives a value and sets a signal depending on it.

This allows you to create APIs that take any kind of SignalSetter<T> as an argument, rather than adding a generic F: Fn(T). Values can be set with the same function call or set(), API as other signals.

§Core Trait Implementations

  • .set() (or calling the setter as a function) sets the signal’s value, and notifies all subscribers that the signal’s value has changed. to subscribe to the signal, and to re-run whenever the value of the signal changes.

§Examples

let (count, set_count) = signal(2);
let set_double_input = SignalSetter::map(move |n| set_count.set(n * 2));

// this function takes any kind of signal setter
fn set_to_4(setter: &SignalSetter<i32>) {
    // ✅ calling the signal sets the value
    //    can be `setter(4)` on nightly
    setter.set(4);
}

set_to_4(&set_count.into());
assert_eq!(count.get(), 4);
set_to_4(&set_double_input);
assert_eq!(count.get(), 8);

Implementations§

Source§

impl<T, S> SignalSetter<T, S>
where S: Storage<Box<dyn Fn(T) + Send + Sync>>,

Source

pub fn map(mapped_setter: impl Fn(T) + Send + Sync + 'static) -> Self

Wraps a signal-setting closure, i.e., any computation that sets one or more reactive signals.

Trait Implementations§

Source§

impl<T, S> Clone for SignalSetter<T, S>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T, S: Debug> Debug for SignalSetter<T, S>
where T: 'static + Debug,

Source§

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

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

impl<T: Default + 'static, S> Default for SignalSetter<T, S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, S> Fn(T) for SignalSetter<T, S>
where SignalSetter<T, S>: Set<Value = T>,

Source§

extern "rust-call" fn call(&self, args: (T,)) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
Source§

impl<T, S> FnMut(T) for SignalSetter<T, S>
where SignalSetter<T, S>: Set<Value = T>,

Source§

extern "rust-call" fn call_mut(&mut self, args: (T,)) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
Source§

impl<T, S> FnOnce(T) for SignalSetter<T, S>
where SignalSetter<T, S>: Set<Value = T>,

Source§

type Output = ()

The returned type after the call operator is used.
Source§

extern "rust-call" fn call_once(self, args: (T,)) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
Source§

impl<T, S> From<RwSignal<T, S>> for SignalSetter<T, S>
where T: Send + Sync + 'static, S: Storage<ArcRwSignal<T>> + Storage<ArcWriteSignal<T>>,

Source§

fn from(value: RwSignal<T, S>) -> Self

Converts to this type from the input type.
Source§

impl<T, S> From<WriteSignal<T, S>> for SignalSetter<T, S>

Source§

fn from(value: WriteSignal<T, S>) -> Self

Converts to this type from the input type.
Source§

impl<T, S: PartialEq> PartialEq for SignalSetter<T, S>
where T: 'static + PartialEq,

Source§

fn eq(&self, other: &SignalSetter<T, S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, S> Set for SignalSetter<T, S>
where T: 'static, S: Storage<ArcWriteSignal<T>> + Storage<Box<dyn Fn(T) + Send + Sync>>,

Source§

type Value = T

The type of the value contained in the signal.
Source§

fn set(&self, new_value: Self::Value)

Updates the value by replacing it, and notifies subscribers that it has changed.
Source§

fn try_set(&self, new_value: Self::Value) -> Option<Self::Value>

Updates the value by replacing it, and notifies subscribers that it has changed. Read more
Source§

impl<T, S> Copy for SignalSetter<T, S>

Source§

impl<T, S: Eq> Eq for SignalSetter<T, S>
where T: 'static + Eq,

Source§

impl<T, S> StructuralPartialEq for SignalSetter<T, S>
where T: 'static,

Auto Trait Implementations§

§

impl<T, S> Freeze for SignalSetter<T, S>

§

impl<T, S> RefUnwindSafe for SignalSetter<T, S>

§

impl<T, S> Send for SignalSetter<T, S>

§

impl<T, S> Sync for SignalSetter<T, S>

§

impl<T, S> Unpin for SignalSetter<T, S>

§

impl<T, S> UnwindSafe for SignalSetter<T, S>

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<Func, T> EffectFunction<T, SingleParam> for Func
where Func: FnMut(Option<T>) -> T,

Source§

fn run(&mut self, p: Option<T>) -> T

Call this to execute the function. In case the actual function has no parameters the parameter p will simply be ignored.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T, S> IntoSignalSetter<T, S> for F
where F: Fn(T) + 'static + Send + Sync, S: Storage<Box<dyn Fn(T) + Send + Sync>>,

Source§

fn into_signal_setter(self) -> SignalSetter<T, S>

Consumes self, returning SignalSetter<T>.
Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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 = 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more