pub trait OutSlot: 'static {
type Destination: DestinationUse;
const NAME: &'static str;
// Provided method
fn outgoing() -> Vec<OutgoingMessageMetadata> { ... }
}Expand description
A slot marker: the identity of one Out injection.
Markers decouple a handler signature from the concrete publisher type: the handler names the
slot, the include site names the policy, and the runtime pairs them. Derive it on a unit
struct with #[derive(OutSlot)] (macros feature); NAME labels the slot in
startup errors and test assertions.
§Examples
use ruststream::memory::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
struct Order {
id: u64,
}
#[derive(Serialize, Outgoing)]
#[outgoing(name = "audit")]
struct Audited {
id: u64,
}
/// The slot the handler names; `Audit` is how startup errors and `tb.out::<Audit>()` call it.
#[derive(OutSlot)]
#[publishes(Audited)]
struct Audit;
#[subscriber("orders")]
async fn accept(order: &Order, Out(audit): Out<impl Publisher, Audit>) -> HandlerOutcome {
match audit.message(&Audited { id: order.id }).publish().await {
Ok(()) => HandlerOutcome::ack(),
Err(_) => HandlerOutcome::retry(),
}
}
fn app() -> RustStream {
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
b.include(accept).out(Audit, Publish).build();
})
}Required Associated Constants§
Required Associated Types§
Sourcetype Destination: DestinationUse
type Destination: DestinationUse
The most a transform on this slot may do to a message’s destination.
Names only where every type the slot publishes leaves its destination open, because a
type that fixes its own channel is published there and the generated document says so.
#[derive(OutSlot)] folds this out of the #[publishes(..)] list through
ListOffer; a marker with no list has nothing to fold and writes Reads, which is
what the implicit DefaultSlot does - it admits every message, so it can promise
nothing. Stable Rust has no default for an associated type, so every marker writes the
line.
Provided Methods§
Sourcefn outgoing() -> Vec<OutgoingMessageMetadata>
fn outgoing() -> Vec<OutgoingMessageMetadata>
The slot’s publish dictionary as AsyncAPI metadata, one entry per
#[publishes(..)] type. The derive fills this in; the default (a marker without a
dictionary) publishes nothing declared. Called once at registration; never on the
publish path.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".