pub mod data;
pub mod guard;
pub mod handler;
pub mod request;
pub mod response;
pub mod route;
pub mod server;
pub mod header;
pub mod util;
pub use faithea_macro::*;
pub use http::HeaderMap;
use crate::handler::types::HttpHandlerError;
pub mod websocket;
#[macro_export]
macro_rules! map_str {
() => {
|x| format!("{}", x)
};
}
#[macro_export]
macro_rules! map_fu {
() => {
|x| Box::new(format!("{}", x)) as HttpHandlerError
};
}
pub fn regulate_url_path<T: AsRef<str>>(s: T) -> String {
let a: &str = s.as_ref();
let mut v = a.into();
if !a.starts_with("/") {
v = format!("/{}", a);
}
if v.ends_with("/") && v.len() != 1 {
v.pop();
}
v.to_string()
}
#[cfg(test)]
mod test {
}
#[macro_export]
macro_rules! res_modifiers {
($($e:expr),*) => {
{
let a:Vec<Box<dyn $crate::response::HttpResponseModifier + Send + Sync>> = vec![
$( Box::new($e),)*
];
a
}
};
}
pub trait TryConvertFrom<T>: Sized {
fn try_convert_from(value: T) -> Result<Self, HttpHandlerError>;
}
pub trait TryConvertInto<O> {
fn try_convert_into(self) -> Result<O, HttpHandlerError>;
}
impl<O, T: TryConvertFrom<O>> TryConvertInto<T> for O {
fn try_convert_into(self) -> Result<T, HttpHandlerError> {
T::try_convert_from(self)
}
}
#[cfg(test)]
mod tests {
use http::{HeaderMap, StatusCode};
#[test]
fn macro_test() {
let s = StatusCode::OK;
let h = HeaderMap::new();
let _ = res_modifiers!(s,h);
}
}