Struct shades::When[][src]

pub struct When<'a, R> { /* fields omitted */ }

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]

pub fn or_else(
    self,
    condition: impl Into<Expr<bool>>,
    body: impl FnOnce(&mut EscapeScope<R>)
) -> Self
[src]

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

impl<'a, R: Debug> Debug for When<'a, R>[src]

Auto Trait Implementations

impl<'a, R> RefUnwindSafe for When<'a, R> where
    R: RefUnwindSafe
[src]

impl<'a, R> Send for When<'a, R> where
    R: Send
[src]

impl<'a, R> Sync for When<'a, R> where
    R: Sync
[src]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.