use crate::http::{Response, Status};
use std::borrow::Cow;
pub trait Responsable: Send + 'static {
fn to_response(self) -> Response;
}
impl Responsable for &'static str {
fn to_response(self) -> Response {
Response::ok().html(self)
}
}
impl Responsable for String {
fn to_response(self) -> Response {
Response::ok().html(self)
}
}
impl Responsable for Cow<'static, str> {
fn to_response(self) -> Response {
Response::ok().html(self)
}
}
impl Responsable for Box<str> {
fn to_response(self) -> Response {
Response::ok().html(self.to_string())
}
}
impl<T: Responsable> Responsable for (Status, T) {
fn to_response(self) -> Response {
let mut res = self.1.to_response();
res.set_status(self.0);
res
}
}
impl Responsable for () {
fn to_response(self) -> Response {
Response::ok()
}
}
impl<T: Responsable> Responsable for (u16, T) {
fn to_response(self) -> Response {
let mut res = self.1.to_response();
if let Some(status) = Status::from_code(self.0) {
res.set_status(status);
}
res
}
}