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§
Implementations on Foreign Types§
Source§impl IntoResponse for &str
impl IntoResponse for &str
Source§impl IntoResponse for Value
Available on crate feature json only.
impl IntoResponse for Value
Available on crate feature
json only.