[][src]Macro portal::path

macro_rules! path {
    ($($pieces:tt)*) => { ... };
}

Convenient way to chain multiple path filters together.

Any number of either type identifiers or string expressions can be passed, each separated by a forward slash (/). Strings will be used to match path segments exactly, and type identifiers are used just like param filters.

Example

use portal::Filter;

// Match `/sum/:a/:b`
let route = portal::path!("sum" / u32 / u32)
    .map(|a, b| {
        format!("{} + {} = {}", a, b, a + b)
    });

The equivalent filter chain without using the path! macro looks this:

use portal::Filter;

let route = portal::path("sum")
    .and(portal::path::param::<u32>())
    .and(portal::path::param::<u32>())
    .and(portal::path::end())
    .map(|a, b| {
        format!("{} + {} = {}", a, b, a + b)
    });

Path Prefixes

The path! macro automatically assumes the path should include an end() filter. To build up a path filter prefix, such that the end() isn't included, use the / .. syntax.

use portal::Filter;

let prefix = portal::path!("math" / "sum" / ..);

let sum = portal::path!(u32 / u32)
    .map(|a, b| {
        format!("{} + {} = {}", a, b, a + b)
    });

let help = portal::path::end()
    .map(|| "This API returns the sum of two u32's");

let api = prefix.and(sum.or(help));