[][src]Module ructe::Template_syntax::c_Conditionals

Both @if statements with boolean expressions, @if let guard statements, and @match statements are supported.

Conditionals

Rust-like conditionals are supported in a style similar to the loops:

@if items.is_empty() {
  <p>There are no items.</p>
}

Pattern matching let expressions are also supported, as well as an optional else part.

@if let Some(foo) = foo {
  <p>Foo is @foo.</p>
} else {
  <p>There is no foo.</p>
}

The condition or let expression should allow anything that would be allowed in the same place in plain rust. As with loops, the things in the curly brackets are ructe template code.

match

Pattern matching using match statements are also supported.

@match answer {
  Ok(value) => {
    <p>The answer is @value.</p>
  }
  Err(_) => {
    <p>I don't know the answer.</p>
  }
}

The let expression and patterns should allow anything that would be allowed in the same place in plain rust. As above, the things in the curly brackets are ructe template code.