use crate::TryFromConn;
use trillium::{async_trait, Conn};
#[async_trait]
pub trait FromConn: Send + Sync + Sized + 'static {
async fn from_conn(conn: &mut Conn) -> Option<Self>;
}
#[async_trait]
impl FromConn for () {
async fn from_conn(_: &mut Conn) -> Option<Self> {
Some(())
}
}
#[async_trait]
impl<E: FromConn> FromConn for Option<E> {
async fn from_conn(conn: &mut Conn) -> Option<Self> {
Some(E::from_conn(conn).await)
}
}
#[async_trait]
impl<T, E> FromConn for Result<T, E>
where
T: TryFromConn<Error = E>,
E: Send + Sync + 'static,
{
async fn from_conn(conn: &mut Conn) -> Option<Self> {
Some(T::try_from_conn(conn).await)
}
}
#[async_trait]
impl FromConn for trillium::Headers {
async fn from_conn(conn: &mut Conn) -> Option<Self> {
Some(conn.request_headers().clone())
}
}
#[async_trait]
impl FromConn for trillium::Method {
async fn from_conn(conn: &mut Conn) -> Option<Self> {
Some(conn.method())
}
}