1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::convert::Infallible;
use crate::{async_trait, IntoResponse, Request};
#[async_trait]
pub trait FromRequest: Sized {
    type Error: IntoResponse;
    #[must_use]
    async fn extract(req: &mut Request) -> Result<Self, Self::Error>;
}
#[async_trait]
impl<T> FromRequest for Option<T>
where
    T: FromRequest,
{
    type Error = Infallible;
    #[inline]
    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 = Infallible;
    #[inline]
    async fn extract(req: &mut Request) -> Result<Self, Self::Error> {
        Ok(T::extract(req).await)
    }
}