本页尚未翻译
下面显示的是英文原文。
Outgoing
A message type names its header contract, so publishing it does not compile without the headers.
#[outgoing(headers = Meta)] makes the contract part of the message type, the type's MessageHeaders contract.
Its publish does not compile without .with_headers(&meta).
The manual form implements MessageHeaders by hand and names the contract as its Contract; a type with none names NoHeaders.
An Out slot lists the types it may publish in #[publishes(..)], and each keeps its own contract, as on the Slots page.
The handler on the Headers page publishes a ChunkDone through such a slot.
Example
- Macros
- Manual
/// A chunk: publishing one does not compile without its `ChunkMeta`.
#[derive(Debug, PartialEq, Serialize, Deserialize, Outgoing)]
#[outgoing(name = "chunks", headers = ChunkMeta)]
struct Chunk {
size: u64,
}
/// A finished chunk: publishing one does not compile without its `DoneMeta`.
#[derive(Debug, PartialEq, Serialize, Deserialize, Outgoing)]
#[outgoing(name = "chunks.done", headers = DoneMeta)]
struct ChunkDone {
output_key: String,
}
/// A chunk: publishing one does not compile without its `ChunkMeta`.
#[derive(Debug, PartialEq, Serialize, Deserialize, schemars::JsonSchema)]
struct Chunk {
size: u64,
}
impl OutgoingDestination for Chunk {
type Form = FixedName;
const DESTINATION: &'static str = "chunks";
}
impl MessageHeaders for Chunk {
type Contract = WithHeaders<ChunkMeta>;
}
/// A finished chunk: publishing one does not compile without its `DoneMeta`.
#[derive(Debug, PartialEq, Serialize, Deserialize, schemars::JsonSchema)]
struct ChunkDone {
output_key: String,
}
impl OutgoingDestination for ChunkDone {
type Form = FixedName;
const DESTINATION: &'static str = "chunks.done";
}
impl MessageHeaders for ChunkDone {
type Contract = WithHeaders<DoneMeta>;
}
- Macros
- Manual
/// The slot the converter publishes through, and what it may publish.
#[derive(OutSlot)]
#[publishes(ChunkDone)]
struct Events;
/// The slot the converter publishes through, and what it may publish.
struct Events;
impl OutSlot for Events {
const NAME: &'static str = "Events";
type Destination = Reads;
fn outgoing() -> Vec<OutgoingMessageMetadata> {
<ChunkDone as OutMessages<Self>>::outgoing()
}
}
impl PublishedThrough<Events> for ChunkDone {}
impl<M: OutSlot> OutMessages<M> for ChunkDone {
fn outgoing() -> Vec<OutgoingMessageMetadata> {
vec![OutgoingMessageMetadata::new(
Self::DESTINATION,
type_name::<Self>(),
)]
}
}