Enum reactive_graph::wrappers::read::MaybeSignal

source ·
pub enum MaybeSignal<T, S = SyncStorage>
where T: 'static,
{ Static(T), Dynamic(Signal<T, S>), }
Expand description

A wrapper for a value that is either T or Signal<T>.

This allows you to create APIs that take either a reactive or a non-reactive value of the same type. This is especially useful for component properties.

let (count, set_count) = signal(2);
let double_count = MaybeSignal::derive(move || count.get() * 2);
let memoized_double_count = Memo::new(move |_| count.get() * 2);
let static_value = 5;

// this function takes either a reactive or non-reactive value
fn above_3(arg: &MaybeSignal<i32>) -> bool {
    // ✅ calling the signal clones and returns the value
    //    it is a shorthand for arg.get()
    arg.get() > 3
}

assert_eq!(above_3(&static_value.into()), true);
assert_eq!(above_3(&count.into()), false);
assert_eq!(above_3(&double_count), true);
assert_eq!(above_3(&memoized_double_count.into()), true);

Variants§

§

Static(T)

An unchanging value of type T.

§

Dynamic(Signal<T, S>)

A reactive signal that contains a value of type T.

Implementations§

source§

impl<T> MaybeSignal<T>
where T: Send + Sync,

source

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

Wraps a derived signal, i.e., any computation that accesses one or more reactive signals.

source§

impl<T> MaybeSignal<T, LocalStorage>

source

pub fn derive_local(derived_signal: impl Fn() -> T + 'static) -> Self

Wraps a derived signal, i.e., any computation that accesses one or more reactive signals.

Trait Implementations§

source§

impl<T: Clone, S> Clone for MaybeSignal<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 MaybeSignal<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, S> Default for MaybeSignal<T, S>

source§

fn default() -> Self

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

impl<T, S> DefinedAt for MaybeSignal<T, S>

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<'de, T: Deserialize<'de>, S> Deserialize<'de> for MaybeSignal<T, S>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

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

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, S> FnMut() for MaybeSignal<T, S>
where MaybeSignal<T, S>: Get,

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, S> FnOnce() for MaybeSignal<T, S>
where MaybeSignal<T, S>: Get,

§

type Output = <MaybeSignal<T, S> 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<S> From<&str> for MaybeSignal<String, S>

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

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

source§

fn from(value: ArcMemo<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<ArcRwSignal<T>> for MaybeSignal<T>
where T: Send + Sync + 'static,

source§

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

Converts to this type from the input type.
source§

impl<T> From<MaybeSignal<Option<T>>> for MaybeProp<T>

source§

fn from(value: MaybeSignal<Option<T>>) -> Self

Converts to this type from the input type.
source§

impl<T> From<MaybeSignal<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>

source§

fn from(value: MaybeSignal<Option<T>, LocalStorage>) -> Self

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

impl<T> From<Memo<T, LocalStorage>> for MaybeSignal<T, LocalStorage>

source§

fn from(value: Memo<T, LocalStorage>) -> Self

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

impl<T> From<ReadSignal<T, LocalStorage>> for MaybeSignal<T, LocalStorage>

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

impl<T> From<RwSignal<T, LocalStorage>> for MaybeSignal<T, LocalStorage>

source§

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

Converts to this type from the input type.
source§

impl<T, S> From<Signal<T, S>> for MaybeSignal<T, S>

source§

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

Converts to this type from the input type.
source§

impl<T, S> From<T> for MaybeSignal<T, S>

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

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

source§

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

Converts between the types.
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<ArcRwSignal<T>> for MaybeSignal<T, LocalStorage>
where T: 'static,

source§

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

Converts between the types.
source§

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, St> Serialize for MaybeSignal<T, St>
where T: Send + Sync + Serialize, St: Storage<SignalTypes<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, S> With for MaybeSignal<T, S>
where T: Send + Sync + 'static, S: Storage<SignalTypes<T>>,

§

type Value = T

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

fn try_with<U>(&self, fun: impl FnOnce(&Self::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, S> WithUntracked for MaybeSignal<T, S>
where S: Storage<SignalTypes<T>>,

§

type Value = T

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

fn try_with_untracked<U>( &self, fun: impl FnOnce(&Self::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
source§

impl<T: Copy, S> Copy for MaybeSignal<T, S>

source§

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

source§

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

Auto Trait Implementations§

§

impl<T, S> Freeze for MaybeSignal<T, S>
where T: Freeze,

§

impl<T, S = SyncStorage> !RefUnwindSafe for MaybeSignal<T, S>

§

impl<T, S> Send for MaybeSignal<T, S>
where T: Send, S: Send,

§

impl<T, S> Sync for MaybeSignal<T, S>
where T: Sync, S: Sync,

§

impl<T, S> Unpin for MaybeSignal<T, S>
where T: Unpin, S: Unpin,

§

impl<T, S = SyncStorage> !UnwindSafe for MaybeSignal<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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,