pub mod app;
pub mod handler;
pub mod macros;
pub(crate) mod path;
pub(crate) mod router;
use http::{Request, Response};
use std::{collections::BTreeMap, pin::Pin};
pub type Params = BTreeMap<String, String>;
pub(crate) type PinBox<F> = Pin<Box<F>>;
#[derive(Debug, Clone)]
pub struct ServerError(String);
impl<T> From<T> for ServerError
where
T: ToString,
{
fn from(t: T) -> Self {
ServerError(t.to_string())
}
}
#[derive(Clone, Debug)]
pub enum Error {
StatusCode(http::StatusCode, String),
InternalServerError(String),
}
impl Default for Error {
fn default() -> Self {
Self::InternalServerError("internal server error".to_string())
}
}
impl Error {
pub fn new<T>(message: T) -> Self
where
T: ToString,
{
Self::InternalServerError(message.to_string())
}
pub fn new_status<T>(error: http::StatusCode, message: T) -> Self
where
T: ToString,
{
Self::StatusCode(error, message.to_string())
}
}
impl<T> From<T> for Error
where
T: ToString,
{
fn from(t: T) -> Self {
Self::new(t.to_string())
}
}
pub trait ToStatus
where
Self: ToString,
{
fn to_status(&self) -> Error;
}
pub type HTTPResult<TransientState> = Result<
(
Request<hyper::Body>,
Option<Response<hyper::Body>>,
TransientState,
),
Error,
>;
pub trait TransientState
where
Self: Clone + Send,
{
fn initial() -> Self;
}
#[derive(Clone)]
pub struct NoState;
impl TransientState for NoState {
fn initial() -> Self {
Self {}
}
}
pub mod prelude {
pub use crate::{
app::App, compose_handler, Error, HTTPResult, NoState, Params, ServerError, ToStatus,
TransientState,
};
pub use http::{Request, Response, StatusCode};
pub use hyper::Body;
}