IntoResponse

Trait IntoResponse 

Source
pub trait IntoResponse {
    // Required method
    fn into_response(
        self,
    ) -> Result<Response<String>, Box<dyn StdError + Send + Sync>>;
}
Expand description

Trait for values that can be transformed into Result<Response<String>, BoxError>

All implementations of this trait can be used as the return type for the future passed to crate::CaseBuilder::returning.

§Examples

§String-types

String-types will use their value as the response body, with a status code of 200.

// &str
let some_str = "some_str";
let res = some_str.into_response();

// Static
let some_string = "some_string".to_string();
let res = some_string.into_response();

§Status and string-types

You can pass a status code by passing a value that implements TryInto<StatusCode>.

let status = 400;
let body = "FILE NOT FOUND";
let res = (status, body).into_response();

§JSON payloads

This is only supported when the json feature flag is set.

let payload = json!({ "message": "some response" });
let res = payload.into_response();

Required Methods§

Source

fn into_response( self, ) -> Result<Response<String>, Box<dyn StdError + Send + Sync>>

Transforms self into a Result<Response<String>, BoxError>

Implementations on Foreign Types§

Source§

impl IntoResponse for &str

Source§

impl IntoResponse for Value

Available on crate feature json only.
Source§

impl IntoResponse for String

Source§

impl<B> IntoResponse for Response<B>
where B: ToString,

Source§

impl<R, E> IntoResponse for Result<R, E>
where R: IntoResponse, E: StdError + Send + Sync + 'static,

Source§

impl<S, B> IntoResponse for (S, B)
where S: TryInto<StatusCode> + 'static, S::Error: StdError + Send + Sync + 'static, B: ToString + 'static,

Implementors§