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§
Trait Implementations§
Source§impl<T, S> Clone for SignalSetter<T, S>
impl<T, S> Clone for SignalSetter<T, S>
Source§impl<T: Default + 'static, S> Default for SignalSetter<T, S>
impl<T: Default + 'static, S> Default for SignalSetter<T, S>
Source§impl<T, S> Fn(T) for SignalSetter<T, S>where
SignalSetter<T, S>: Set<Value = T>,
impl<T, S> Fn(T) for SignalSetter<T, S>where
SignalSetter<T, S>: Set<Value = T>,
Source§impl<T, S> FnMut(T) for SignalSetter<T, S>where
SignalSetter<T, S>: Set<Value = T>,
impl<T, S> FnMut(T) for SignalSetter<T, S>where
SignalSetter<T, S>: Set<Value = T>,
Source§impl<T, S> FnOnce(T) for SignalSetter<T, S>where
SignalSetter<T, S>: Set<Value = T>,
impl<T, S> FnOnce(T) for SignalSetter<T, S>where
SignalSetter<T, S>: Set<Value = T>,
Source§impl<T, S> From<RwSignal<T, S>> for SignalSetter<T, S>
impl<T, S> From<RwSignal<T, S>> for SignalSetter<T, S>
Source§impl<T, S> From<WriteSignal<T, S>> for SignalSetter<T, S>
impl<T, S> From<WriteSignal<T, S>> for SignalSetter<T, S>
Source§fn from(value: WriteSignal<T, S>) -> Self
fn from(value: WriteSignal<T, S>) -> Self
Converts to this type from the input type.
Source§impl<T, S> Set for SignalSetter<T, S>
impl<T, S> Set for SignalSetter<T, S>
impl<T, S> Copy for SignalSetter<T, S>
impl<T, S: Eq> Eq for SignalSetter<T, S>where
T: 'static + Eq,
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Func, T> EffectFunction<T, SingleParam> for Func
impl<Func, T> EffectFunction<T, SingleParam> for Func
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<F, T, S> IntoSignalSetter<T, S> for F
impl<F, T, S> IntoSignalSetter<T, S> for F
Source§fn into_signal_setter(self) -> SignalSetter<T, S>
fn into_signal_setter(self) -> SignalSetter<T, S>
Consumes
self
, returning SignalSetter<T>
.Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Borrows the value.
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Takes the value.