use crate::response::Response;
pub trait IntoResponse: Send {
fn into_response(self) -> Response;
}
impl IntoResponse for String {
fn into_response(self) -> Response {
Response::text(self)
}
}
impl IntoResponse for &'static str {
fn into_response(self) -> Response {
Response::text(self)
}
}
impl IntoResponse for std::borrow::Cow<'static, str> {
fn into_response(self) -> Response {
Response::text(self)
}
}
impl IntoResponse for Response {
fn into_response(self) -> Response {
self
}
}
impl IntoResponse for () {
fn into_response(self) -> Response {
Response::empty()
}
}
impl<T: IntoResponse> IntoResponse for Option<T> {
fn into_response(self) -> Response {
match self {
Some(value) => value.into_response(),
None => Response::empty(),
}
}
}
impl<T: IntoResponse, E: std::fmt::Display + Send> IntoResponse for Result<T, E> {
fn into_response(self) -> Response {
match self {
Ok(value) => value.into_response(),
Err(e) => Response::text(format!("Error: {}", e)),
}
}
}
impl IntoResponse for async_fs::File {
fn into_response(self) -> Response {
Response::file(self)
}
}
impl IntoResponse for (async_fs::File, &'static str) {
fn into_response(self) -> Response {
Response::file(self.0).with_caption(self.1)
}
}
impl IntoResponse for (async_fs::File, String) {
fn into_response(self) -> Response {
Response::file(self.0).with_caption(self.1)
}
}