8000 GitHub - AnthIste/iron-defer: Attempt at combining handlers for the Rust web framework Iron
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

AnthIste/iron-defer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

iron-defer

Attempt at combining handlers for the Rust web framework iron.

Usage

use std::error::Error;
use std::fmt;

use iron::prelude::*;
use iron::status;

#[derive(Debug)]
struct DummyError;

impl Error for DummyError {
    fn description(&self) -> &'static str { "DummyError" }
}

impl fmt::Display for DummyError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(self.description())
    }
}

#[test]
fn it_works() {
    /// Returning `Ok` uses the original response
    /// Returning `Err` makes the `about` handler take over.
    fn hello_world(_: &mut Request) -> IronResult<Response> {
        // Ok(Response::with((status::Ok, "Hello world")))
        Err(IronError::new(DummyError, status::NotFound))
    }

    fn about(_: &mut Request) -> IronResult<Response> {
        Ok(Response::with((status::Ok, "About")))
    }

    let defer = Defer::using(hello_world, about);

    Iron::new(defer).listen("localhost:3000").unwrap();
}

About

Attempt at combining handlers for the Rust web framework Iron

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0