pub struct If<T, F> { /* private fields */ }
Expand description
A conditional view that can take on one of at most two branches, depending on a boolean condition.
Implementations§
Source§impl<T> If<T, ()>
impl<T> If<T, ()>
Sourcepub fn new(condition: bool, then_view: impl FnOnce() -> T) -> If<T, ()>
pub fn new(condition: bool, then_view: impl FnOnce() -> T) -> If<T, ()>
Examples found in repository?
examples/fizz_buzz.rs (line 29)
19 fn body(&self) -> Self::Body {
20 let count = self.count.clone();
21 let fizz = count.get() % 3 == 0;
22 let buzz = count.get() % 5 == 0;
23 VStack::new((
24 Button::with_text("Increment", clone!(count => move || {
25 count.set(count.get() + 1);
26 })),
27 If::new_or_else(fizz || buzz, || {
28 HStack::new((
29 If::new(fizz, || Text::new("Fizz")),
30 If::new(buzz, || Text::new("Buzz")),
31 ))
32 }, || {
33 Text::new(format!("{}", self.count.get()))
34 }),
35 ))
36 }
Source§impl<T, F> If<T, F>
impl<T, F> If<T, F>
Sourcepub fn new_or_else(
condition: bool,
then_view: impl FnOnce() -> T,
else_view: impl FnOnce() -> F,
) -> If<T, F>
pub fn new_or_else( condition: bool, then_view: impl FnOnce() -> T, else_view: impl FnOnce() -> F, ) -> If<T, F>
Examples found in repository?
examples/fizz_buzz.rs (lines 27-34)
19 fn body(&self) -> Self::Body {
20 let count = self.count.clone();
21 let fizz = count.get() % 3 == 0;
22 let buzz = count.get() % 5 == 0;
23 VStack::new((
24 Button::with_text("Increment", clone!(count => move || {
25 count.set(count.get() + 1);
26 })),
27 If::new_or_else(fizz || buzz, || {
28 HStack::new((
29 If::new(fizz, || Text::new("Fizz")),
30 If::new(buzz, || Text::new("Buzz")),
31 ))
32 }, || {
33 Text::new(format!("{}", self.count.get()))
34 }),
35 ))
36 }
Trait Implementations§
impl<T, F> Eq for If<T, F>
impl<T, F> StructuralPartialEq for If<T, F>
Auto Trait Implementations§
impl<T, F> Freeze for If<T, F>
impl<T, F> RefUnwindSafe for If<T, F>where
T: RefUnwindSafe,
F: RefUnwindSafe,
impl<T, F> Send for If<T, F>
impl<T, F> Sync for If<T, F>
impl<T, F> Unpin for If<T, F>
impl<T, F> UnwindSafe for If<T, F>where
T: UnwindSafe,
F: UnwindSafe,
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