nest_rs_queue/queue_name.rs
1//! Compile-time queue identity.
2//!
3//! A queue's name is otherwise a bare string repeated on both sides —
4//! `#[process(queue = "audio")]` on the consumer, `push_json("audio", …)` on
5//! the producer — with nothing linking the two literals or the payload type
6//! either side agrees on. [`QueueName`] turns that identity into a **type**
7//! that carries both facts: the wire name ([`QueueName::NAME`]) and the job
8//! type ([`QueueName::Job`]). Declared once at the feature port next to the
9//! [`Job`] payload with the [`queue`](crate::queue) attribute macro, it is the
10//! single artifact producer and consumer both import — so a typo or a
11//! mismatched payload becomes a compile error instead of a job that silently
12//! never drains.
13
14use crate::processor::Job;
15
16/// The type-level identity of a queue: its wire name plus the [`Job`] payload
17/// it carries. Implemented by the [`queue`](crate::queue) macro on a unit
18/// struct living beside the payload at the feature port:
19///
20/// ```
21/// use nest_rs_queue::{queue, QueueName};
22///
23/// // Any `T: Serialize + DeserializeOwned + Clone + Send + Sync + Unpin` is a
24/// // `Job`; a real feature uses its own `TranscodeCommand` payload struct.
25/// #[queue(name = "transcode", job = String)]
26/// struct TranscodeQueue;
27///
28/// assert_eq!(<TranscodeQueue as QueueName>::NAME, "transcode");
29/// ```
30///
31/// Both sides then name the *type*, not the string:
32/// [`push_to`](crate::JobProducerExt::push_to) on the producer and
33/// `#[process(queue = TranscodeQueue)]` on the consumer. The macro asserts the
34/// process method's job argument is `Self::Job`, so a mismatch is a compile
35/// error naming both types.
36pub trait QueueName: 'static {
37 /// The wire name apalis (or any backend) namespaces storage under — the
38 /// exact string a legacy `#[process(queue = "…")]` literal would carry.
39 const NAME: &'static str;
40
41 /// The payload type pushed onto and drained off this queue. The producer's
42 /// `push_to::<Self>` accepts exactly this type; the consumer's
43 /// `#[process(queue = Self)]` method must receive exactly this type.
44 type Job: Job;
45}