Add an example to Rocket::catch docs.

This commit is contained in:
Sergio Benitez 2016-11-05 19:35:21 +01:00
parent 2cc0251a22
commit 006a35a8a9
1 changed files with 28 additions and 0 deletions

View File

@ -320,6 +320,34 @@ impl Rocket {
}
/// Registers all of the catchers in the supplied vector.
///
/// # Examples
///
/// ```rust
/// #![feature(plugin)]
/// #![plugin(rocket_codegen)]
///
/// extern crate rocket;
///
/// use rocket::Request;
///
/// #[error(500)]
/// fn internal_error() -> &'static str {
/// "Whoops! Looks like we messed up."
/// }
///
/// #[error(400)]
/// fn not_found(req: &Request) -> String {
/// format!("I couldn't find '{}'. Try something else?", req.uri())
/// }
///
/// fn main() {
/// # if false { // We don't actually want to launch the server in an example.
/// rocket::ignite().catch(errors![internal_error, not_found])
/// # .launch()
/// # }
/// }
/// ```
pub fn catch(mut self, catchers: Vec<Catcher>) -> Self {
info!("👾 {}:", Magenta.paint("Catchers"));
for c in catchers {