pub trait IntoResponse {
    // Required method
    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§

source

fn into_response(self, state: &State) -> Response<Body>

Converts this value into a hyper::Response

Implementations on Foreign Types§

source§

impl IntoResponse for String

source§

impl IntoResponse for Cow<'static, str>

source§

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

source§

impl IntoResponse for Bytes

source§

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

source§

impl IntoResponse for &'static [u8]

source§

impl IntoResponse for Vec<u8>

source§

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

source§

impl IntoResponse for Response<Body>

source§

fn into_response(self, _state: &State) -> Response<Body>

source§

impl<T, E> IntoResponse for Result<T, E>where T: IntoResponse, E: IntoResponse,

source§

impl IntoResponse for &'static str

Implementors§