pub struct MaybeProp<T, S = SyncStorage>(/* private fields */)
where
T: 'static,
S: Storage<Option<T>> + Storage<SignalTypes<Option<T>, S>>;Expand description
A wrapping type for an optional component prop.
This can either be a signal or a non-reactive value, and may or may not have a value.
In other words, this is an Option<Signal<Option<T>>>, but automatically flattens its getters.
This creates an extremely flexible type for component libraries, etc.
§Examples
let (count, set_count) = signal(Some(2));
let double = |n| n * 2;
let double_count = MaybeProp::derive(move || count.get().map(double));
let memoized_double_count = Memo::new(move |_| count.get().map(double));
let static_value = 5;
// this function takes either a reactive or non-reactive value
fn above_3(arg: &MaybeProp<i32>) -> bool {
// ✅ calling the signal clones and returns the value
// it is a shorthand for arg.get()q
arg.get().map(|arg| arg > 3).unwrap_or(false)
}
assert_eq!(above_3(&None::<i32>.into()), false);
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);Implementations§
Source§impl<T> MaybeProp<T, LocalStorage>
impl<T> MaybeProp<T, LocalStorage>
Sourcepub fn derive_local(
derived_signal: impl Fn() -> Option<T> + 'static,
) -> MaybeProp<T, LocalStorage>
pub fn derive_local( derived_signal: impl Fn() -> Option<T> + 'static, ) -> MaybeProp<T, LocalStorage>
Wraps a derived signal, i.e., any computation that accesses one or more reactive signals.
Trait Implementations§
impl<T, S> Copy for MaybeProp<T, S>
Source§impl<T, S> DefinedAt for MaybeProp<T, S>
impl<T, S> DefinedAt for MaybeProp<T, S>
Source§fn defined_at(&self) -> Option<&'static Location<'static>>
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.impl<T, S> Eq for MaybeProp<T, S>
Source§impl<T> From<MaybeProp<T, LocalStorage>> for Option<Signal<Option<T>, LocalStorage>>
impl<T> From<MaybeProp<T, LocalStorage>> for Option<Signal<Option<T>, LocalStorage>>
Source§fn from(
value: MaybeProp<T, LocalStorage>,
) -> Option<Signal<Option<T>, LocalStorage>>
fn from( value: MaybeProp<T, LocalStorage>, ) -> Option<Signal<Option<T>, LocalStorage>>
Converts to this type from the input type.
Source§impl<T> From<MaybeSignal<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>
impl<T> From<MaybeSignal<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>
Source§fn from(
value: MaybeSignal<Option<T>, LocalStorage>,
) -> MaybeProp<T, LocalStorage>
fn from( value: MaybeSignal<Option<T>, LocalStorage>, ) -> MaybeProp<T, LocalStorage>
Converts to this type from the input type.
Source§impl<T> From<Memo<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>
impl<T> From<Memo<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>
Source§fn from(value: Memo<Option<T>, LocalStorage>) -> MaybeProp<T, LocalStorage>
fn from(value: Memo<Option<T>, LocalStorage>) -> MaybeProp<T, LocalStorage>
Converts to this type from the input type.
Source§impl<T> From<Memo<T, LocalStorage>> for MaybeProp<T, LocalStorage>
impl<T> From<Memo<T, LocalStorage>> for MaybeProp<T, LocalStorage>
Source§fn from(value: Memo<T, LocalStorage>) -> MaybeProp<T, LocalStorage>
fn from(value: Memo<T, LocalStorage>) -> MaybeProp<T, LocalStorage>
Converts to this type from the input type.
Source§impl<T> From<Option<MaybeSignal<Option<T>, LocalStorage>>> for MaybeProp<T, LocalStorage>
impl<T> From<Option<MaybeSignal<Option<T>, LocalStorage>>> for MaybeProp<T, LocalStorage>
Source§fn from(
value: Option<MaybeSignal<Option<T>, LocalStorage>>,
) -> MaybeProp<T, LocalStorage>
fn from( value: Option<MaybeSignal<Option<T>, LocalStorage>>, ) -> MaybeProp<T, LocalStorage>
Converts to this type from the input type.
Source§impl<T> From<ReadSignal<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>
impl<T> From<ReadSignal<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>
Source§fn from(
value: ReadSignal<Option<T>, LocalStorage>,
) -> MaybeProp<T, LocalStorage>
fn from( value: ReadSignal<Option<T>, LocalStorage>, ) -> MaybeProp<T, LocalStorage>
Converts to this type from the input type.
Source§impl<T> From<ReadSignal<T, LocalStorage>> for MaybeProp<T, LocalStorage>
impl<T> From<ReadSignal<T, LocalStorage>> for MaybeProp<T, LocalStorage>
Source§fn from(value: ReadSignal<T, LocalStorage>) -> MaybeProp<T, LocalStorage>
fn from(value: ReadSignal<T, LocalStorage>) -> MaybeProp<T, LocalStorage>
Converts to this type from the input type.
Source§impl<T> From<ReadSignal<T>> for MaybeProp<T>
impl<T> From<ReadSignal<T>> for MaybeProp<T>
Source§fn from(value: ReadSignal<T>) -> MaybeProp<T>
fn from(value: ReadSignal<T>) -> MaybeProp<T>
Converts to this type from the input type.
Source§impl<T> From<RwSignal<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>
impl<T> From<RwSignal<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>
Source§fn from(value: RwSignal<Option<T>, LocalStorage>) -> MaybeProp<T, LocalStorage>
fn from(value: RwSignal<Option<T>, LocalStorage>) -> MaybeProp<T, LocalStorage>
Converts to this type from the input type.
Source§impl<T> From<RwSignal<T, LocalStorage>> for MaybeProp<T, LocalStorage>
impl<T> From<RwSignal<T, LocalStorage>> for MaybeProp<T, LocalStorage>
Source§fn from(value: RwSignal<T, LocalStorage>) -> MaybeProp<T, LocalStorage>
fn from(value: RwSignal<T, LocalStorage>) -> MaybeProp<T, LocalStorage>
Converts to this type from the input type.
Source§impl<T> From<Signal<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>
impl<T> From<Signal<Option<T>, LocalStorage>> for MaybeProp<T, LocalStorage>
Source§fn from(value: Signal<Option<T>, LocalStorage>) -> MaybeProp<T, LocalStorage>
fn from(value: Signal<Option<T>, LocalStorage>) -> MaybeProp<T, LocalStorage>
Converts to this type from the input type.
Source§impl<T> From<Signal<T, LocalStorage>> for MaybeProp<T, LocalStorage>
impl<T> From<Signal<T, LocalStorage>> for MaybeProp<T, LocalStorage>
Source§fn from(value: Signal<T, LocalStorage>) -> MaybeProp<T, LocalStorage>
fn from(value: Signal<T, LocalStorage>) -> MaybeProp<T, LocalStorage>
Converts to this type from the input type.
Source§impl<T> FromLocal<Option<T>> for MaybeProp<T, LocalStorage>
impl<T> FromLocal<Option<T>> for MaybeProp<T, LocalStorage>
Source§fn from_local(value: Option<T>) -> MaybeProp<T, LocalStorage>
fn from_local(value: Option<T>) -> MaybeProp<T, LocalStorage>
Converts between the types.
Source§impl<T> FromLocal<T> for MaybeProp<T, LocalStorage>
impl<T> FromLocal<T> for MaybeProp<T, LocalStorage>
Source§fn from_local(value: T) -> MaybeProp<T, LocalStorage>
fn from_local(value: T) -> MaybeProp<T, LocalStorage>
Converts between the types.
Source§impl<T, S> ReadUntracked for MaybeProp<T, S>
impl<T, S> ReadUntracked for MaybeProp<T, S>
Source§type Value = ReadGuard<Option<T>, SignalReadGuard<Option<T>, S>>
type Value = ReadGuard<Option<T>, SignalReadGuard<Option<T>, S>>
The guard type that will be returned, which can be dereferenced to the value.
Source§fn try_read_untracked(
&self,
) -> Option<<MaybeProp<T, S> as ReadUntracked>::Value>
fn try_read_untracked( &self, ) -> Option<<MaybeProp<T, S> as ReadUntracked>::Value>
Returns the guard, or
None if the signal has already been disposed.Source§fn custom_try_read(
&self,
) -> Option<Option<<MaybeProp<T, S> as ReadUntracked>::Value>>
fn custom_try_read( &self, ) -> Option<Option<<MaybeProp<T, S> as ReadUntracked>::Value>>
This is a backdoor to allow overriding the
Read::try_read implementation despite it being auto implemented. Read moreSource§fn read_untracked(&self) -> Self::Value
fn read_untracked(&self) -> Self::Value
Returns the guard. Read more
Source§impl<T, St> Serialize for MaybeProp<T, St>
impl<T, St> Serialize for MaybeProp<T, St>
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<T, S> StructuralPartialEq for MaybeProp<T, S>
Auto Trait Implementations§
impl<T, S> Freeze for MaybeProp<T, S>
impl<T, S> RefUnwindSafe for MaybeProp<T, S>
impl<T, S> Send for MaybeProp<T, S>
impl<T, S> Sync for MaybeProp<T, S>
impl<T, S> Unpin for MaybeProp<T, S>
impl<T, S> UnsafeUnpin for MaybeProp<T, S>
impl<T, S> UnwindSafe for MaybeProp<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
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<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§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<S, T> FromStream<T> for S
impl<S, T> FromStream<T> for S
Source§fn from_stream(stream: impl Stream<Item = T> + Send + 'static) -> S
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
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
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<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<CustErr, T, Response> IntoRes<Json, Response, CustErr> for T
impl<CustErr, T, Response> IntoRes<Json, Response, CustErr> for T
Source§async fn into_res(self) -> Result<Response, ServerFnError<CustErr>>
async fn into_res(self) -> Result<Response, ServerFnError<CustErr>>
Attempts to serialize the output into an HTTP response.
Source§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Read for Twhere
T: Track + ReadUntracked,
impl<T> Read for Twhere
T: Track + ReadUntracked,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
impl<T> SerializableAny 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.
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
Source§impl<S, T> Upcast<T> for S
impl<S, T> Upcast<T> for S
impl<T> WasmNotSend for Twhere
T: Send,
impl<T> WasmNotSendSync for Twhere
T: WasmNotSend + WasmNotSync,
impl<T> WasmNotSync for Twhere
T: Sync,
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
The type of the value contained in the signal.
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
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>
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.