Skip to main content

JobProducerExt

Trait JobProducerExt 

Source
pub trait JobProducerExt: JobProducer {
    // Provided methods
    fn push_to<'life0, 'async_trait, Q>(
        &'life0 self,
        job: Q::Job,
    ) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>
       where Q: 'async_trait + QueueName,
             Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
    fn push<'life0, 'life1, 'async_trait, J>(
        &'life0 self,
        queue: &'life1 str,
        job: J,
    ) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>
       where J: 'async_trait + Job + Serialize,
             Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Typed-push convenience over any JobProducer. Lives as an extension trait so the producer trait stays object-safe (Arc<dyn JobProducer>).

Provided Methods§

Source

fn push_to<'life0, 'async_trait, Q>( &'life0 self, job: Q::Job, ) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>
where Q: 'async_trait + QueueName, Self: Sync + 'async_trait, 'life0: 'async_trait,

Push a job onto a typed queue handle — the default enqueue path. The queue name and the payload type are both taken from Q (QueueName::NAME and QueueName::Job), so the compiler rejects an enqueue onto the wrong queue or with the wrong payload before it ever runs. Declare Q once at the feature port with the queue macro; both the producer here and the consumer’s #[process(queue = Q)] name the same type.

Fails with QueueError::Serialize if the job won’t serialize, else with whatever push_json returns.

Passing a job of the wrong type is a compile error, not a runtime surprise:

use nest_rs_queue::{queue, JobProducer, JobProducerExt};

#[queue(name = "transcode", job = String)]
struct TranscodeQueue;

async fn demo<P: JobProducer>(producer: &P) {
    // `TranscodeQueue::Job` is `String`; a `u32` does not compile.
    producer.push_to::<TranscodeQueue>(42u32).await.unwrap();
}
Source

fn push<'life0, 'life1, 'async_trait, J>( &'life0 self, queue: &'life1 str, job: J, ) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>
where J: 'async_trait + Job + Serialize, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Push a job onto a queue named by a raw string — the dynamic-name escape hatch. Prefer push_to: a typed handle compile-checks both the name and the payload type. Reach for this only when the queue name genuinely isn’t known until runtime. Fails with QueueError::Serialize if the job won’t serialize, else with whatever push_json returns.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§