JobCallExt

Trait JobCallExt 

Source
pub trait JobCallExt: Sized + Sealed {
    // Required methods
    fn extract<E, M>(
        self,
    ) -> impl Future<Output = Result<E, <E as FromJobCall<(), M>>::Rejection>> + Send
       where E: FromJobCall<(), M> + 'static,
             M: 'static;
    fn extract_with_context<E, Ctx, M>(
        self,
        ctx: &Ctx,
    ) -> impl Future<Output = Result<E, <E as FromJobCall<Ctx, M>>::Rejection>> + Send
       where E: FromJobCall<Ctx, M> + 'static,
             Ctx: Send + Sync;
    fn extract_parts<E>(
        &mut self,
    ) -> impl Future<Output = Result<E, <E as FromJobCallParts<()>>::Rejection>> + Send
       where E: FromJobCallParts<()> + 'static;
    fn extract_parts_with_context<'a, E, Ctx>(
        &'a mut self,
        ctx: &'a Ctx,
    ) -> impl Future<Output = Result<E, <E as FromJobCallParts<Ctx>>::Rejection>> + Send + 'a
       where E: FromJobCallParts<Ctx> + 'static,
             Ctx: Send + Sync;
}
Expand description

Extension trait that adds additional methods to JobCall.

Required Methods§

Source

fn extract<E, M>( self, ) -> impl Future<Output = Result<E, <E as FromJobCall<(), M>>::Rejection>> + Send
where E: FromJobCall<(), M> + 'static, M: 'static,

Apply an extractor to this JobCall.

This is just a convenience for E::from_job_call(call, &()).

Note this consumes the job call. Use JobCallExt::extract_parts() if you’re not extracting the body and don’t want to consume the job call.

Source

fn extract_with_context<E, Ctx, M>( self, ctx: &Ctx, ) -> impl Future<Output = Result<E, <E as FromJobCall<Ctx, M>>::Rejection>> + Send
where E: FromJobCall<Ctx, M> + 'static, Ctx: Send + Sync,

Apply an extractor that requires some context to this JobCall.

This is just a convenience for E::from_job_call(call, ctx).

Note this consumes the job call. Use JobCallExt::extract_parts_with_context() if you’re not extracting the body and don’t want to consume the job call.

§Example
use blueprint_sdk::extract::{FromJobCall, FromRef};
use blueprint_sdk::{JobCall, JobCallExt};

struct MyExtractor {
    requires_context: RequiresContext,
}

impl<Ctx> FromJobCall<Ctx> for MyExtractor
where
    String: FromRef<Ctx>,
    Ctx: Send + Sync,
{
    type Rejection = std::convert::Infallible;

    async fn from_job_call(call: JobCall, context: &Ctx) -> Result<Self, Self::Rejection> {
        let requires_context = call.extract_with_context::<RequiresContext, _, _>(context).await?;

        Ok(Self { requires_context })
    }
}

// some extractor that consumes the call body and requires a context
struct RequiresContext { /* ... */ }

impl<Ctx> FromJobCall<Ctx> for RequiresContext
where
    String: FromRef<Ctx>,
    Ctx: Send + Sync,
{
    // ...
}
Source

fn extract_parts<E>( &mut self, ) -> impl Future<Output = Result<E, <E as FromJobCallParts<()>>::Rejection>> + Send
where E: FromJobCallParts<()> + 'static,

Apply a Parts extractor to this JobCall.

This is just a convenience for E::from_job_call_parts(parts, ctx).

Source

fn extract_parts_with_context<'a, E, Ctx>( &'a mut self, ctx: &'a Ctx, ) -> impl Future<Output = Result<E, <E as FromJobCallParts<Ctx>>::Rejection>> + Send + 'a
where E: FromJobCallParts<Ctx> + 'static, Ctx: Send + Sync,

Apply a Parts extractor that requires some state to this Request.

This is just a convenience for E::from_job_call_parts(parts, ctx).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§