pub struct ArcRwSignal<T> { /* private fields */ }
Expand description
A reference-counted signal that can be read from or written to.
A signal is a piece of data that may change over time, and notifies other code when it has changed. This is the atomic unit of reactivity, which begins all other processes of reactive updates.
This is a reference-counted signal, which is Clone
but not Copy
.
For arena-allocated Copy
signals, use RwSignal
.
§Core Trait Implementations
§Reading the Value
.get()
clones the current value of the signal. If you call it within an effect, it will cause that effect to subscribe to the signal, and to re-run whenever the value of the signal changes..get_untracked()
clones the value of the signal without reactively tracking it.
.read()
returns a guard that allows accessing the value of the signal by reference. If you call it within an effect, it will cause that effect to subscribe to the signal, and to re-run whenever the value of the signal changes..read_untracked()
gives access to the current value of the signal without reactively tracking it.
.with()
allows you to reactively access the signal’s value without cloning by applying a callback function..with_untracked()
allows you to access the signal’s value by applying a callback function without reactively tracking it.
.to_stream()
converts the signal to anasync
stream of values.
§Updating the Value
.set()
sets the signal to a new value..update()
updates the value of the signal by applying a closure that takes a mutable reference..write()
returns a guard through which the signal can be mutated, and which notifies subscribers when it is dropped.
Each of these has a related
_untracked()
method, which updates the signal without notifying subscribers. Untracked updates are not desirable in most cases, as they cause “tearing” between the signal’s value and its observed value. If you want a non-reactive container, usedArenaItem
instead.
§Examples
let count = ArcRwSignal::new(0);
// ✅ calling the getter clones and returns the value
// this can be `count()` on nightly
assert_eq!(count.get(), 0);
// ✅ calling the setter sets the value
// this can be `set_count(1)` on nightly
count.set(1);
assert_eq!(count.get(), 1);
// ❌ you could call the getter within the setter
// set_count.set(count.get() + 1);
// ✅ however it's more efficient to use .update() and mutate the value in place
count.update(|count: &mut i32| *count += 1);
assert_eq!(count.get(), 2);
// ✅ you can create "derived signals" with a Fn() -> T interface
let double_count = {
// clone before moving into the closure because we use it below
let count = count.clone();
move || count.get() * 2
};
count.set(0);
assert_eq!(double_count(), 0);
count.set(1);
assert_eq!(double_count(), 2);
Implementations§
Source§impl<T> ArcRwSignal<T>
impl<T> ArcRwSignal<T>
Sourcepub fn read_only(&self) -> ArcReadSignal<T>
pub fn read_only(&self) -> ArcReadSignal<T>
Returns a read-only handle to the signal.
Sourcepub fn write_only(&self) -> ArcWriteSignal<T>
pub fn write_only(&self) -> ArcWriteSignal<T>
Returns a write-only handle to the signal.
Sourcepub fn split(&self) -> (ArcReadSignal<T>, ArcWriteSignal<T>)
pub fn split(&self) -> (ArcReadSignal<T>, ArcWriteSignal<T>)
Splits the signal into its readable and writable halves.
Sourcepub fn unite(read: ArcReadSignal<T>, write: ArcWriteSignal<T>) -> Option<Self>
pub fn unite(read: ArcReadSignal<T>, write: ArcWriteSignal<T>) -> Option<Self>
Reunites the two halves of a signal. Returns None
if the two signals
provided were not created from the same signal.
Trait Implementations§
Source§impl<T> Clone for ArcRwSignal<T>
impl<T> Clone for ArcRwSignal<T>
Source§impl<T> Debug for ArcRwSignal<T>
impl<T> Debug for ArcRwSignal<T>
Source§impl<T> Default for ArcRwSignal<T>where
T: Default,
impl<T> Default for ArcRwSignal<T>where
T: Default,
Source§impl<T> DefinedAt for ArcRwSignal<T>
impl<T> DefinedAt for ArcRwSignal<T>
Source§fn defined_at(&self) -> Option<&'static Location<'static>>
fn defined_at(&self) -> Option<&'static Location<'static>>
None
in
release mode.Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for ArcRwSignal<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for ArcRwSignal<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<T> Fn() for ArcRwSignal<T>where
ArcRwSignal<T>: Get,
impl<T> Fn() for ArcRwSignal<T>where
ArcRwSignal<T>: Get,
Source§impl<T> Fn(T) for ArcRwSignal<T>where
ArcRwSignal<T>: Set<Value = T>,
impl<T> Fn(T) for ArcRwSignal<T>where
ArcRwSignal<T>: Set<Value = T>,
Source§impl<T> FnMut() for ArcRwSignal<T>where
ArcRwSignal<T>: Get,
impl<T> FnMut() for ArcRwSignal<T>where
ArcRwSignal<T>: Get,
Source§impl<T> FnMut(T) for ArcRwSignal<T>where
ArcRwSignal<T>: Set<Value = T>,
impl<T> FnMut(T) for ArcRwSignal<T>where
ArcRwSignal<T>: Set<Value = T>,
Source§impl<T> FnOnce() for ArcRwSignal<T>where
ArcRwSignal<T>: Get,
impl<T> FnOnce() for ArcRwSignal<T>where
ArcRwSignal<T>: Get,
Source§impl<T> FnOnce(T) for ArcRwSignal<T>where
ArcRwSignal<T>: Set<Value = T>,
impl<T> FnOnce(T) for ArcRwSignal<T>where
ArcRwSignal<T>: Set<Value = T>,
Source§impl<'a, T> From<&'a ArcRwSignal<T>> for RwSignal<T>
impl<'a, T> From<&'a ArcRwSignal<T>> for RwSignal<T>
Source§fn from(value: &'a ArcRwSignal<T>) -> Self
fn from(value: &'a ArcRwSignal<T>) -> Self
Source§impl<T> From<ArcRwSignal<T>> for ArcMemo<T, SyncStorage>
impl<T> From<ArcRwSignal<T>> for ArcMemo<T, SyncStorage>
Source§fn from(value: ArcRwSignal<T>) -> Self
fn from(value: ArcRwSignal<T>) -> Self
Source§impl<T: Send + Sync> From<ArcRwSignal<T>> for ArcSignal<T, SyncStorage>
impl<T: Send + Sync> From<ArcRwSignal<T>> for ArcSignal<T, SyncStorage>
Source§fn from(value: ArcRwSignal<T>) -> Self
fn from(value: ArcRwSignal<T>) -> Self
Source§impl<T> From<ArcRwSignal<T>> for MaybeSignal<T>
impl<T> From<ArcRwSignal<T>> for MaybeSignal<T>
Source§fn from(value: ArcRwSignal<T>) -> Self
fn from(value: ArcRwSignal<T>) -> Self
Source§impl<T> From<ArcRwSignal<T>> for RwSignal<T>
impl<T> From<ArcRwSignal<T>> for RwSignal<T>
Source§fn from(value: ArcRwSignal<T>) -> Self
fn from(value: ArcRwSignal<T>) -> Self
Source§impl<T> From<ArcRwSignal<T>> for Signal<T>
impl<T> From<ArcRwSignal<T>> for Signal<T>
Source§fn from(value: ArcRwSignal<T>) -> Self
fn from(value: ArcRwSignal<T>) -> Self
Source§impl<T> From<ArcRwSignal<T>> for Signal<T, LocalStorage>
impl<T> From<ArcRwSignal<T>> for Signal<T, LocalStorage>
Source§fn from(value: ArcRwSignal<T>) -> Self
fn from(value: ArcRwSignal<T>) -> Self
Source§impl<T, S> From<RwSignal<T, S>> for ArcRwSignal<T>where
T: 'static,
S: Storage<ArcRwSignal<T>>,
impl<T, S> From<RwSignal<T, S>> for ArcRwSignal<T>where
T: 'static,
S: Storage<ArcRwSignal<T>>,
Source§impl<T> FromLocal<ArcRwSignal<T>> for MaybeSignal<T, LocalStorage>where
T: 'static,
impl<T> FromLocal<ArcRwSignal<T>> for MaybeSignal<T, LocalStorage>where
T: 'static,
Source§fn from_local(value: ArcRwSignal<T>) -> Self
fn from_local(value: ArcRwSignal<T>) -> Self
Source§impl<T> FromLocal<ArcRwSignal<T>> for RwSignal<T, LocalStorage>where
T: 'static,
impl<T> FromLocal<ArcRwSignal<T>> for RwSignal<T, LocalStorage>where
T: 'static,
Source§fn from_local(value: ArcRwSignal<T>) -> Self
fn from_local(value: ArcRwSignal<T>) -> Self
Source§impl<T> Hash for ArcRwSignal<T>
impl<T> Hash for ArcRwSignal<T>
Source§impl<T> IntoInner for ArcRwSignal<T>
impl<T> IntoInner for ArcRwSignal<T>
Source§impl<T> IsDisposed for ArcRwSignal<T>
impl<T> IsDisposed for ArcRwSignal<T>
Source§fn is_disposed(&self) -> bool
fn is_disposed(&self) -> bool
true
, the signal cannot be accessed without a panic.Source§impl<T> Notify for ArcRwSignal<T>
impl<T> Notify for ArcRwSignal<T>
Source§impl<T> PartialEq for ArcRwSignal<T>
impl<T> PartialEq for ArcRwSignal<T>
Source§impl<T: 'static> ReadUntracked for ArcRwSignal<T>
impl<T: 'static> ReadUntracked for ArcRwSignal<T>
Source§type Value = ReadGuard<T, Plain<T>>
type Value = ReadGuard<T, Plain<T>>
Source§fn try_read_untracked(&self) -> Option<Self::Value>
fn try_read_untracked(&self) -> Option<Self::Value>
None
if the signal has already been disposed.Source§fn read_untracked(&self) -> Self::Value
fn read_untracked(&self) -> Self::Value
Source§fn custom_try_read(&self) -> Option<Option<Self::Value>>
fn custom_try_read(&self) -> Option<Option<Self::Value>>
Read::try_read
implementation despite it being auto implemented. Read moreSource§impl<T: Serialize + 'static> Serialize for ArcRwSignal<T>
impl<T: Serialize + 'static> Serialize for ArcRwSignal<T>
Source§impl<T: 'static> Write for ArcRwSignal<T>
impl<T: 'static> Write for ArcRwSignal<T>
Source§fn try_write(&self) -> Option<impl UntrackableGuard<Target = Self::Value>>
fn try_write(&self) -> Option<impl UntrackableGuard<Target = Self::Value>>
None
if the signal has already been disposed.Source§fn try_write_untracked(&self) -> Option<UntrackedWriteGuard<Self::Value>>
fn try_write_untracked(&self) -> Option<UntrackedWriteGuard<Self::Value>>
None
if the signal has already been disposed.impl<T> Eq for ArcRwSignal<T>
Auto Trait Implementations§
impl<T> Freeze for ArcRwSignal<T>
impl<T> RefUnwindSafe for ArcRwSignal<T>
impl<T> Send for ArcRwSignal<T>
impl<T> Sync for ArcRwSignal<T>
impl<T> Unpin for ArcRwSignal<T>
impl<T> UnwindSafe for ArcRwSignal<T>
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
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>
self
, returning SignalSetter<T>
.Source§impl<T> ReactiveNode for Twhere
T: AsSubscriberSet + DefinedAt,
impl<T> ReactiveNode for Twhere
T: AsSubscriberSet + DefinedAt,
Source§fn mark_dirty(&self)
fn mark_dirty(&self)
Source§fn mark_check(&self)
fn mark_check(&self)
Source§fn mark_subscribers_check(&self)
fn mark_subscribers_check(&self)
Source§fn update_if_necessary(&self) -> bool
fn update_if_necessary(&self) -> bool
Source§impl<T> Read for Twhere
T: Track + ReadUntracked,
impl<T> Read for Twhere
T: Track + ReadUntracked,
Source§impl<T> Set for Twhere
T: Update + IsDisposed,
impl<T> Set for Twhere
T: Update + IsDisposed,
Source§impl<T> Source for Twhere
T: AsSubscriberSet + DefinedAt,
impl<T> Source for Twhere
T: AsSubscriberSet + DefinedAt,
Source§fn clear_subscribers(&self)
fn clear_subscribers(&self)
Source§fn add_subscriber(&self, subscriber: AnySubscriber)
fn add_subscriber(&self, subscriber: AnySubscriber)
Source§fn remove_subscriber(&self, subscriber: &AnySubscriber)
fn remove_subscriber(&self, subscriber: &AnySubscriber)
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Source§impl<T> Update for Twhere
T: Write,
impl<T> Update for Twhere
T: Write,
Source§fn try_maybe_update<U>(
&self,
fun: impl FnOnce(&mut <T as Update>::Value) -> (bool, U),
) -> Option<U>
fn try_maybe_update<U>( &self, fun: impl FnOnce(&mut <T as Update>::Value) -> (bool, U), ) -> Option<U>
(true, _)
, and returns the value returned by the update function,
or None
if the signal has already been disposed.Source§fn update(&self, fun: impl FnOnce(&mut Self::Value))
fn update(&self, fun: impl FnOnce(&mut Self::Value))
Source§impl<T> UpdateUntracked for Twhere
T: Write,
impl<T> UpdateUntracked for Twhere
T: Write,
Source§fn try_update_untracked<U>(
&self,
fun: impl FnOnce(&mut <T as UpdateUntracked>::Value) -> U,
) -> Option<U>
fn try_update_untracked<U>( &self, fun: impl FnOnce(&mut <T as UpdateUntracked>::Value) -> U, ) -> Option<U>
None
if the signal has already been disposed.
Does not notify subscribers that the signal has changed.Source§impl<T> With for Twhere
T: Read,
impl<T> With for Twhere
T: Read,
Source§type Value = <<T as Read>::Value as Deref>::Target
type Value = <<T as Read>::Value as Deref>::Target
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<T> WithUntracked for Twhere
T: DefinedAt + ReadUntracked,
impl<T> WithUntracked for Twhere
T: DefinedAt + ReadUntracked,
Source§type Value = <<T as ReadUntracked>::Value as Deref>::Target
type Value = <<T as ReadUntracked>::Value as Deref>::Target
Source§fn try_with_untracked<U>(
&self,
fun: impl FnOnce(&<T as WithUntracked>::Value) -> U,
) -> Option<U>
fn try_with_untracked<U>( &self, fun: impl FnOnce(&<T as WithUntracked>::Value) -> U, ) -> Option<U>
None
if the signal has already been disposed.