use crate::{async_trait, IntoResponse, Request};
#[async_trait]
pub trait FromRequest: Sized {
type Error: IntoResponse;
async fn extract(req: &mut Request) -> Result<Self, Self::Error>;
}
#[async_trait]
impl<T> FromRequest for Option<T>
where
T: FromRequest,
{
type Error = std::convert::Infallible;
async fn extract(req: &mut Request) -> Result<Self, Self::Error> {
Ok(T::extract(req).await.ok())
}
}
#[async_trait]
impl<T> FromRequest for Result<T, T::Error>
where
T: FromRequest,
{
type Error = std::convert::Infallible;
async fn extract(req: &mut Request) -> Result<Self, Self::Error> {
Ok(T::extract(req).await)
}
}