Trait gotham::handler::IntoResponse
source · [−]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())
}
tree.add_route(Box::new(route));
Router::new(tree, finalizer);
Required methods
fn into_response(self, state: &State) -> Response<Body>
fn into_response(self, state: &State) -> Response<Body>
Converts this value into a hyper::Response