[][src]Macro vial::run

macro_rules! run {
    () => { ... };
    ($addr:expr) => { ... };
    ($($module:ident),+) => { ... };
    ($addr:expr, $($module:ident),+) => { ... };
}

The vial::run! macro is the preferred way of starting your Vial application after you've defined one or more routes using vial::routes!. run! performs a bit of necessary setup, then starts listening for client requests at http://0.0.0.0:7667 by default.

There are four ways to use run!:

  1. vial::run!(): No arguments. Starts listening at http://0.0.0.0:7667 and expects you to have called vial::routes! in the current module.

  2. vial::run!("localhost:9999"): With your own address.

  3. vial::run!(blog, wiki): With modules that you've called vial::routes! from within. This will combine all the routes.

    For example:

mod wiki {
    vial::routes! {
        GET "/wiki" => |_| Response::from_file("wiki.html");
    }
}

mod blog {
    vial::routes! {
        GET "/blog" => show_blog;
        // etc...
    }

    fn show_blog(req: vial::Request) -> String {
        // ...
        "blog".to_string()
    }
}

fn main() {
    vial::run!(wiki, blog).unwrap();
}
  1. Using a combination of the above:

fn main() {
    vial::run!("localhost:1111", blog, wiki).unwrap();
}