rama_http/service/web/endpoint/extract/
option.rsuse std::future::Future;
use rama_core::Context;
use crate::response::IntoResponse;
use crate::{dep::http::request::Parts, Request};
use super::{FromRequest, FromRequestContextRefPair};
pub trait OptionalFromRequestContextRefPair<S>: Sized + Send + Sync + 'static {
type Rejection: IntoResponse;
fn from_request_context_ref_pair(
ctx: &Context<S>,
parts: &Parts,
) -> impl Future<Output = Result<Option<Self>, Self::Rejection>> + Send;
}
pub trait OptionalFromRequest: Sized + Send + Sync + 'static {
type Rejection: IntoResponse;
fn from_request(
req: Request,
) -> impl Future<Output = Result<Option<Self>, Self::Rejection>> + Send;
}
impl<S, T> FromRequestContextRefPair<S> for Option<T>
where
T: OptionalFromRequestContextRefPair<S>,
S: Send + Sync,
{
type Rejection = T::Rejection;
fn from_request_context_ref_pair(
ctx: &Context<S>,
parts: &Parts,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send {
T::from_request_context_ref_pair(ctx, parts)
}
}
impl<T> FromRequest for Option<T>
where
T: OptionalFromRequest,
{
type Rejection = T::Rejection;
async fn from_request(req: Request) -> Result<Option<T>, Self::Rejection> {
T::from_request(req).await
}
}