use core::future::Future;
use crate::extract::{FromJobCall, FromJobCallParts, JobCall, private};
use crate::job::call::Parts;
use crate::job::result::IntoJobResult;
pub trait OptionalFromJobCallParts<Ctx>: Sized {
type Rejection: IntoJobResult;
fn from_job_call_parts(
parts: &mut Parts,
ctx: &Ctx,
) -> impl Future<Output = Result<Option<Self>, Self::Rejection>> + Send;
}
pub trait OptionalFromJobCall<Ctx, M = private::ViaJobCall>: Sized {
type Rejection: IntoJobResult;
fn from_job_call(
call: JobCall,
ctx: &Ctx,
) -> impl Future<Output = Result<Option<Self>, Self::Rejection>> + Send;
}
impl<Ctx, T> FromJobCallParts<Ctx> for Option<T>
where
T: OptionalFromJobCallParts<Ctx>,
Ctx: Send + Sync,
{
type Rejection = T::Rejection;
fn from_job_call_parts(
parts: &mut Parts,
ctx: &Ctx,
) -> impl Future<Output = Result<Option<T>, Self::Rejection>> {
T::from_job_call_parts(parts, ctx)
}
}
impl<Ctx, T> FromJobCall<Ctx> for Option<T>
where
T: OptionalFromJobCall<Ctx>,
Ctx: Send + Sync,
{
type Rejection = T::Rejection;
async fn from_job_call(call: JobCall, ctx: &Ctx) -> Result<Option<T>, Self::Rejection> {
T::from_job_call(call, ctx).await
}
}