Macro rocket::catchers

source ยท
catchers!() { /* proc-macro */ }
Expand description

Generates a [Vec] of Catchers from a set of catcher paths.

The catchers! macro expands a list of catcher paths into a [Vec] of their corresponding Catcher structures. For example, given the following catchers:

#[catch(404)]
fn not_found() { /* .. */ }

mod inner {
    #[catch(400)]
    pub fn unauthorized() { /* .. */ }
}

The catchers! macro can be used as:

let my_catchers = catchers![not_found, inner::unauthorized];
assert_eq!(my_catchers.len(), 2);

let not_found = &my_catchers[0];
assert_eq!(not_found.code, 404);

let unauthorized = &my_catchers[1];
assert_eq!(unauthorized.code, 400);

The grammar for catchers! is defined as:

catchers := PATH (',' PATH)*

PATH := a path, as defined by Rust