ArcReadSignal

Struct ArcReadSignal 

Source
pub struct ArcReadSignal<T> { /* private fields */ }
Expand description

A reference-counted getter for a reactive signal.

A signal is a piece of data that may change over time, and notifies other code when it has changed.

This is a reference-counted signal, which is Clone but not Copy. For arena-allocated Copy signals, use ReadSignal.

§Core Trait Implementations

  • .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 an async stream of values.
  • ::from_stream() converts an async stream of values into a signal containing the latest value.

§Examples

let (count, set_count) = arc_signal(0);

// calling .get() clones and returns the value
assert_eq!(count.get(), 0);
// calling .read() accesses the value by reference
assert_eq!(count.read(), 0);

Trait Implementations§

Source§

impl<T> Clone for ArcReadSignal<T>

Source§

fn clone(&self) -> Self

Returns a duplicate 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> Debug for ArcReadSignal<T>

Source§

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

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

impl<T: Default> Default for ArcReadSignal<T>

Source§

fn default() -> Self

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

impl<T> DefinedAt for ArcReadSignal<T>

Source§

fn defined_at(&self) -> Option<&'static Location<'static>>

Returns the location at which the signal was defined. This is usually simply None in release mode.
Source§

impl<T> Fn() for ArcReadSignal<T>
where ArcReadSignal<T>: Get,

Available on crate feature nightly only.
Source§

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

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

impl<T> FnMut() for ArcReadSignal<T>
where ArcReadSignal<T>: Get,

Available on crate feature nightly only.
Source§

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

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

impl<T> FnOnce() for ArcReadSignal<T>
where ArcReadSignal<T>: Get,

Available on crate feature nightly only.
Source§

type Output = <ArcReadSignal<T> as Get>::Value

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

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

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

impl<T> From<ArcReadSignal<T>> for ArcMemo<T, SyncStorage>
where T: Clone + PartialEq + Send + Sync + 'static,

Source§

fn from(value: ArcReadSignal<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Send + Sync> From<ArcReadSignal<T>> for ArcSignal<T, SyncStorage>

Source§

fn from(value: ArcReadSignal<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<ArcReadSignal<T>> for MaybeSignal<T>
where T: Send + Sync,

Source§

fn from(value: ArcReadSignal<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<ArcReadSignal<T>> for Memo<T>
where T: Clone + PartialEq + Send + Sync + 'static,

Source§

fn from(value: ArcReadSignal<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<ArcReadSignal<T>> for ReadSignal<T>
where T: Send + Sync + 'static,

Source§

fn from(value: ArcReadSignal<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<ArcReadSignal<T>> for Signal<T>
where T: Send + Sync + 'static,

Source§

fn from(value: ArcReadSignal<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<ArcReadSignal<T>> for Signal<T, LocalStorage>
where T: Send + Sync + 'static,

Source§

fn from(value: ArcReadSignal<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, S> From<ReadSignal<T, S>> for ArcReadSignal<T>
where T: 'static, S: Storage<ArcReadSignal<T>>,

Source§

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

Converts to this type from the input type.
Source§

impl<T> FromLocal<ArcReadSignal<T>> for MaybeSignal<T, LocalStorage>

Source§

fn from_local(value: ArcReadSignal<T>) -> Self

Converts between the types.
Source§

impl<T> FromLocal<ArcReadSignal<T>> for ReadSignal<T, LocalStorage>
where T: 'static,

Source§

fn from_local(value: ArcReadSignal<T>) -> Self

Converts between the types.
Source§

impl<T> Hash for ArcReadSignal<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> IntoInner for ArcReadSignal<T>

Source§

type Value = T

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

fn into_inner(self) -> Option<Self::Value>

Returns the inner value if this is the only reference to the signal. Otherwise, returns None and drops this reference. Read more
Source§

impl<T> IsDisposed for ArcReadSignal<T>

Source§

fn is_disposed(&self) -> bool

If true, the signal cannot be accessed without a panic.
Source§

impl<T> PartialEq for ArcReadSignal<T>

Source§

fn eq(&self, other: &Self) -> 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: 'static> ReadUntracked for ArcReadSignal<T>

Source§

type Value = ReadGuard<T, Plain<T>>

The guard type that will be returned, which can be dereferenced to the value.
Source§

fn try_read_untracked(&self) -> Option<Self::Value>

Returns the guard, or None if the signal has already been disposed.
Source§

fn read_untracked(&self) -> Self::Value

Returns the guard. Read more
Source§

fn custom_try_read(&self) -> Option<Option<Self::Value>>

This is a backdoor to allow overriding the Read::try_read implementation despite it being auto implemented. Read more
Source§

impl<T: Serialize + 'static> Serialize for ArcReadSignal<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Eq for ArcReadSignal<T>

Auto Trait Implementations§

§

impl<T> Freeze for ArcReadSignal<T>

§

impl<T> RefUnwindSafe for ArcReadSignal<T>

§

impl<T> Send for ArcReadSignal<T>
where T: Send + Sync,

§

impl<T> Sync for ArcReadSignal<T>
where T: Send + Sync,

§

impl<T> Unpin for ArcReadSignal<T>

§

impl<T> UnwindSafe for ArcReadSignal<T>

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

Source§

fn run(&mut self, _: Option<()>)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S, T> FromStream<T> for S
where S: From<ArcReadSignal<Option<T>>> + Send + Sync, T: Send + Sync + 'static,

Source§

fn from_stream(stream: impl Stream<Item = T> + Send + 'static) -> S

Creates a signal that contains the latest value of the stream.
Source§

fn from_stream_unsync(stream: impl Stream<Item = T> + 'static) -> S

Creates a signal that contains the latest value of the stream.
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<T> ReactiveNode for T
where T: AsSubscriberSet + DefinedAt,

Source§

fn mark_dirty(&self)

Notifies the source’s dependencies that it has changed.
Source§

fn mark_check(&self)

Notifies the source’s dependencies that it may have changed.
Source§

fn mark_subscribers_check(&self)

Marks that all subscribers need to be checked.
Source§

fn update_if_necessary(&self) -> bool

Regenerates the value for this node, if needed, and returns whether it has actually changed or not.
Source§

impl<T> Read for T
where T: Track + ReadUntracked,

Source§

type Value = <T as ReadUntracked>::Value

The guard type that will be returned, which can be dereferenced to the value.
Source§

fn try_read(&self) -> Option<<T as Read>::Value>

Subscribes to the signal, and returns the guard, or None if the signal has already been disposed.
Source§

fn read(&self) -> Self::Value

Subscribes to the signal, and returns the guard. Read more
Source§

impl<T> Source for T
where T: AsSubscriberSet + DefinedAt,

Source§

fn clear_subscribers(&self)

Remove all subscribers from this source’s list of dependencies.
Source§

fn add_subscriber(&self, subscriber: AnySubscriber)

Adds a subscriber to this source’s list of dependencies.
Source§

fn remove_subscriber(&self, subscriber: &AnySubscriber)

Removes a subscriber from this source’s list of dependencies.
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> Track for T

Source§

fn track(&self)

Subscribes to this signal in the current reactive scope without doing anything with its value.
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> With for T
where T: Read,

Source§

type Value = <<T as Read>::Value as Deref>::Target

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

fn try_with<U>(&self, fun: impl FnOnce(&<T as With>::Value) -> U) -> Option<U>

Subscribes to the signal, applies the closure to the value, and returns the result, or None if the signal has already been disposed.
Source§

fn with<U>(&self, fun: impl FnOnce(&Self::Value) -> U) -> U

Subscribes to the signal, applies the closure to the value, and returns the result. Read more
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
Source§

impl<T> WithUntracked for T

Source§

type Value = <<T as ReadUntracked>::Value as Deref>::Target

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

fn try_with_untracked<U>( &self, fun: impl FnOnce(&<T as WithUntracked>::Value) -> U, ) -> Option<U>

Applies the closure to the value, and returns the result, or None if the signal has already been disposed.
Source§

fn with_untracked<U>(&self, fun: impl FnOnce(&Self::Value) -> U) -> U

Applies the closure to the value, and returns the result. Read more