Trait gotham::handler::IntoResponse[][src]

pub trait IntoResponse {
    fn into_response(self, state: &State) -> Response<Body>;
}
Expand description

Represents a type which can be converted to a response. This trait is used in converting the return type of a function into a response.

Examples

struct MyStruct {
    value: String,
}

impl MyStruct {
    fn new() -> MyStruct {
        // ...
    }
}

impl IntoResponse for MyStruct {
    fn into_response(self, _state: &State) -> Response<Body> {
        Response::builder()
            .status(StatusCode::OK)
            .body(self.value.into())
            .unwrap()
    }
}

fn handler(state: State) -> (State, MyStruct) {
    (state, MyStruct::new())
}

gotham::start("127.0.0.1:7878", || Ok(handler)).unwrap();

Required methods

Converts this value into a hyper::Response

Implementations on Foreign Types

Implementors