pub struct ShowLetProps<T, ChFn, V, M, __ImplTrait0>where
__ImplTrait0: IntoOptionGetter<T, M>,
ChFn: Fn(T) -> V + Send + Clone + 'static,
V: IntoView + 'static,
T: 'static,{
pub children: ChFn,
pub some: __ImplTrait0,
pub fallback: ViewFn,
pub _marker: PhantomData<(T, M)>,
}Expand description
Props for the ShowLet component.
Like <Show> but for Option. This is a shortcut for
value.map(|value| {
view! { ... }
})If you specify a fallback it is equvalent to
value
.map(
|value| children(value),
)
.unwrap_or_else(fallback)§Example
let (opt_value, set_opt_value) = signal(None::<i32>);
view! {
<ShowLet some=opt_value let:value>
"We have a value: " {value}
</ShowLet>
}You can also specify a fallback:
let (opt_value, set_opt_value) = signal(None::<i32>);
view! {
<ShowLet some=opt_value let:value fallback=|| "Got nothing">
"We have a value: " {value}
</ShowLet>
}In addition to signals you can also use a closure that returns an Option:
let (opt_value, set_opt_value) = signal(None::<i32>);
view! {
<ShowLet some=move || opt_value.get().map(|v| v * 2) let:value>
"We have a value: " {value}
</ShowLet>
}§Required Props
- children: [
ChFn]-
The children will be shown whenever
valueisSome.They take the inner value as an argument. Use
let:to bind the value to a variable.
-
- some: [
__ImplTrait0]- A signal of type
Optionor a closure that returns anOption. If the value isSome, the children will be shown. Otherwise the fallback will be shown, if present.
- A signal of type
§Optional Props
- fallback:
impl Into<ViewFn>-
A closure that returns what gets rendered when the value is
None. By default this is the empty view.You can think of it as the closure inside
.unwrap_or_else(|| fallback()).
-
- _marker:
PhantomData<(T, M)>- Marker for generic parameters. Ignore this.
Fields§
§children: ChFnThe children will be shown whenever value is Some.
They take the inner value as an argument. Use let: to bind the value to a variable.
some: __ImplTrait0A signal of type Option or a closure that returns an Option.
If the value is Some, the children will be shown.
Otherwise the fallback will be shown, if present.
fallback: ViewFnA closure that returns what gets rendered when the value is None.
By default this is the empty view.
You can think of it as the closure inside .unwrap_or_else(|| fallback()).
_marker: PhantomData<(T, M)>Marker for generic parameters. Ignore this.
Implementations§
Source§impl<T, ChFn, V, M, __ImplTrait0> ShowLetProps<T, ChFn, V, M, __ImplTrait0>where
__ImplTrait0: IntoOptionGetter<T, M>,
ChFn: Fn(T) -> V + Send + Clone + 'static,
V: IntoView + 'static,
T: 'static,
impl<T, ChFn, V, M, __ImplTrait0> ShowLetProps<T, ChFn, V, M, __ImplTrait0>where
__ImplTrait0: IntoOptionGetter<T, M>,
ChFn: Fn(T) -> V + Send + Clone + 'static,
V: IntoView + 'static,
T: 'static,
Sourcepub fn builder() -> ShowLetPropsBuilder<T, ChFn, V, M, __ImplTrait0>
pub fn builder() -> ShowLetPropsBuilder<T, ChFn, V, M, __ImplTrait0>
Create a builder for building ShowLetProps.
On the builder, call .children(...), .some(...), .fallback(...)(optional), ._marker(...)(optional) to set the values of the fields.
Finally, call .build() to create the instance of ShowLetProps.
Trait Implementations§
Source§impl<T, ChFn, V, M, __ImplTrait0> Props for ShowLetProps<T, ChFn, V, M, __ImplTrait0>where
__ImplTrait0: IntoOptionGetter<T, M>,
ChFn: Fn(T) -> V + Send + Clone + 'static,
V: IntoView + 'static,
T: 'static,
impl<T, ChFn, V, M, __ImplTrait0> Props for ShowLetProps<T, ChFn, V, M, __ImplTrait0>where
__ImplTrait0: IntoOptionGetter<T, M>,
ChFn: Fn(T) -> V + Send + Clone + 'static,
V: IntoView + 'static,
T: 'static,
Auto Trait Implementations§
impl<T, ChFn, V, M, __ImplTrait0> Freeze for ShowLetProps<T, ChFn, V, M, __ImplTrait0>
impl<T, ChFn, V, M, __ImplTrait0> !RefUnwindSafe for ShowLetProps<T, ChFn, V, M, __ImplTrait0>
impl<T, ChFn, V, M, __ImplTrait0> Send for ShowLetProps<T, ChFn, V, M, __ImplTrait0>
impl<T, ChFn, V, M, __ImplTrait0> Sync for ShowLetProps<T, ChFn, V, M, __ImplTrait0>
impl<T, ChFn, V, M, __ImplTrait0> Unpin for ShowLetProps<T, ChFn, V, M, __ImplTrait0>
impl<T, ChFn, V, M, __ImplTrait0> !UnwindSafe for ShowLetProps<T, ChFn, V, M, __ImplTrait0>
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> 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>
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>
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 more