Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pattern matching with match and case

rust
extern crate oxiplate;

use oxiplate::prelude::*;

#[derive(Oxiplate)]
#[oxiplate_inline(r#"
{%- match value %}
{%- case ..0 -%}
    Less than zero
{%- case 0 -%}
    Zero
{%- case _ -%}
    Greater than zero
{%- endmatch %}"#)]
struct YourStruct {
    value: isize,
}

assert_eq!(
    YourStruct {
        value: -19
    }.render()?,
    "Less than zero"
);

Ok::<(), ::core::fmt::Error>(())