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

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

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>[src]

Converts this value into a hyper::Response

Loading content...

Implementations on Foreign Types

impl IntoResponse for Response<Body>[src]

impl<T, E> IntoResponse for Result<T, E> where
    T: IntoResponse,
    E: IntoResponse
[src]

impl<B> IntoResponse for (Mime, B) where
    B: Into<Body>, 
[src]

impl<B> IntoResponse for (StatusCode, Mime, B) where
    B: Into<Body>, 
[src]

impl IntoResponse for Bytes[src]

impl IntoResponse for String[src]

impl IntoResponse for Vec<u8>[src]

impl IntoResponse for &'static str[src]

impl IntoResponse for &'static [u8][src]

impl IntoResponse for Cow<'static, str>[src]

impl IntoResponse for Cow<'static, [u8]>[src]

Loading content...

Implementors

Loading content...