MaybeSignal

Enum MaybeSignal 

Source
pub enum MaybeSignal<T, S = SyncStorage>
where T: 'static, S: Storage<T>,
{ Static(T), Dynamic(Signal<T, S>), }
๐Ÿ‘ŽDeprecated since 0.7.0-rc3: MaybeSignal<T> is deprecated in favour of Signal<T> which is Copy, now has a more efficient From<T> implementation and other benefits in 0.7.
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)

๐Ÿ‘ŽDeprecated since 0.7.0-rc3: MaybeSignal<T> is deprecated in favour of Signal<T> which is Copy, now has a more efficient From<T> implementation and other benefits in 0.7.

An unchanging value of type T.

ยง

Dynamic(Signal<T, S>)

๐Ÿ‘ŽDeprecated since 0.7.0-rc3: MaybeSignal<T> is deprecated in favour of Signal<T> which is Copy, now has a more efficient From<T> implementation and other benefits in 0.7.

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>
where S: Storage<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, S> Debug for MaybeSignal<T, S>
where T: 'static + Debug, S: Storage<T> + 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>
where S: Storage<T>,

Sourceยง

fn default() -> Self

Returns the โ€œdefault valueโ€ for a type. Read more
Sourceยง

impl<T, S> DefinedAt for MaybeSignal<T, S>
where S: Storage<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<'de, T: Deserialize<'de>, St> Deserialize<'de> for MaybeSignal<T, St>
where St: Storage<T>,

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, S: Storage<T> + Storage<Option<T>> + Storage<SignalTypes<Option<T>, S>>,

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

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

Available on crate feature nightly only.
Sourceยง

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>
where T: Send + Sync, SyncStorage: Storage<Option<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>
where T: Send + Sync,

Sourceยง

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

Converts to this type from the input type.
Sourceยง

impl<T> From<MaybeSignal<T>> for Signal<Option<T>>
where T: Clone + Send + Sync + 'static,

Sourceยง

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

Converts to this type from the input type.
Sourceยง

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

Sourceยง

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

Converts to this type from the input type.
Sourceยง

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

Sourceยง

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

Converts to this type from the input type.
Sourceยง

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

Sourceยง

fn from(value: MaybeSignal<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>
where S: Storage<T>,

Sourceยง

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

Converts to this type from the input type.
Sourceยง

impl<T> From<T> for MaybeSignal<T, SyncStorage>
where SyncStorage: Storage<T>,

Sourceยง

fn from(value: T) -> Self

Converts to this type from the input type.
Sourceยง

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

Sourceยง

fn from_local(value: ArcMemo<T, LocalStorage>) -> 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> FromLocal<T> for MaybeSignal<T, LocalStorage>

Sourceยง

fn from_local(value: T) -> Self

Converts between the types.
Sourceยง

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

Sourceยง

fn eq(&self, other: &MaybeSignal<T, S>) -> 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, S> ReadUntracked for MaybeSignal<T, S>
where T: Clone, S: Storage<SignalTypes<T, S>> + Storage<T>,

Sourceยง

type Value = ReadGuard<T, SignalReadGuard<T, S>>

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 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ยง

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

Returns the guard. Read more
Sourceยง

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

Sourceยง

fn track(&self)

Subscribes to this signal in the current reactive scope without doing anything with its value.
Sourceยง

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

Sourceยง

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

Sourceยง

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

Auto Trait Implementationsยง

ยง

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

ยง

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

ยง

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

ยง

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

ยง

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

ยง

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

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<!> 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> 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> 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, 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
Sourceยง

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