Struct shades::When [−][src]
Conditional combinator.
A When<R>
is returned from functions such as CanEscape::when
or CanEscape::unless
and allows to continue
chaining conditional statements, encoding the concept of else if
and else
in more traditional languages.
Implementations
impl<R> When<'_, R> where
Return: From<R>,
[src]
Return: From<R>,
pub fn or_else(
self,
condition: impl Into<Expr<bool>>,
body: impl FnOnce(&mut EscapeScope<R>)
) -> Self
[src]
self,
condition: impl Into<Expr<bool>>,
body: impl FnOnce(&mut EscapeScope<R>)
) -> Self
Add a conditional branch — else if
.
This method is often found chained after CanEscape::when
and allows to add a new conditional if the previous
conditional fails (i.e. else if
). The behavior is the same as with CanEscape::when
.
Return
Another When<R>
, allowing to add more conditional branches.
Examples
use shades::{CanEscape as _, lit}; let x = lit!(1); // you will need CanEscape in order to use when s.when(x.lt(2), |s| { // do something if x < 2 }).or_else(x.lt(10), |s| { // do something if x < 10 });
pub fn or(self, body: impl FnOnce(&mut EscapeScope<R>))
[src]
Add a final catch-all conditional branch — else
.
This method is often found chained after CanEscape::when
and allows to finish the chain of conditional
branches if the previous conditional fails (i.e. else
). The behavior is the same as with CanEscape::when
.
Examples
use shades::{CanEscape as _, lit}; let x = lit!(1); // you will need CanEscape in order to use when s.when(x.lt(2), |s| { // do something if x < 2 }).or(|s| { // do something if x >= 2 });
Can chain and mix conditional but When::or
cannot be anywhere else but the end of the chain:
use shades::{CanEscape as _, lit}; let x = lit!(1); // you will need CanEscape in order to use when s.when(x.lt(2), |s| { // do something if x < 2 }).or_else(x.lt(5), |s| { // do something if x < 5 }).or_else(x.lt(10), |s| { // do something if x < 10 }).or(|s| { // else, do this });
Trait Implementations
Auto Trait Implementations
impl<'a, R> RefUnwindSafe for When<'a, R> where
R: RefUnwindSafe,
[src]
R: RefUnwindSafe,
impl<'a, R> Send for When<'a, R> where
R: Send,
[src]
R: Send,
impl<'a, R> Sync for When<'a, R> where
R: Sync,
[src]
R: Sync,
impl<'a, R> Unpin for When<'a, R>
[src]
impl<'a, R> !UnwindSafe for When<'a, R>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,