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§fn clone(&self) -> SignalSetter<T, S>
fn clone(&self) -> SignalSetter<T, S>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T, S> Debug for SignalSetter<T, S>
impl<T, S> Debug for SignalSetter<T, S>
Source§impl<T, S> Default for SignalSetter<T, S>where
T: Default + 'static,
impl<T, S> Default for SignalSetter<T, S>where
T: Default + 'static,
Source§fn default() -> SignalSetter<T, S>
fn default() -> SignalSetter<T, S>
Returns the “default value” for a type. Read more
Source§impl<T, S> From<RwSignal<T, S>> for SignalSetter<T, S>
impl<T, S> From<RwSignal<T, S>> for SignalSetter<T, S>
Source§fn from(value: RwSignal<T, S>) -> SignalSetter<T, S>
fn from(value: RwSignal<T, S>) -> SignalSetter<T, S>
Converts to this type from the input type.
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>) -> SignalSetter<T, S>
fn from(value: WriteSignal<T, S>) -> SignalSetter<T, S>
Converts to this type from the input type.
Source§impl<T, S> PartialEq for SignalSetter<T, S>
impl<T, S> PartialEq for SignalSetter<T, S>
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 for SignalSetter<T, S>
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> SerializableKey for T
impl<T> SerializableKey for 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.