pub trait MapPublisher: Sized {
type Policy;
// Required method
fn map_publisher(self, f: impl FnOnce(Self::Policy) -> Self::Policy) -> Self;
}Expand description
Replaces the publish policy of the position a mount chain named last, keeping every step the chain already filled: the hook a broker crate layers its own publisher settings on.
The publish-side mirror of
map_source. Core cannot know that a publish
has an exchange, a partition key or a confirm mode, so the broker declares a trait over the
mount chain bound to its own policy type and implements each method as one map_publisher
call. The bound means those methods simply do not exist on a chain that named another broker’s
policy - or none at all.
A mount site then reads b.include(confirm).out(Reply, StreamPublish::default()).stream("ORDERS"),
and the same one impl serves the reply position and every slot, on a router and on a broker
scope alike.
§Examples
use ruststream::runtime::MapPublisher;
/// A broker's publish policy: the mode, plus the options that shape it. Freely
/// constructible, because it holds no connection.
#[derive(Debug, Clone, Default)]
pub struct StreamPublish {
stream: Option<String>,
expect_last_sequence: Option<u64>,
}
/// What the broker crate ships next to it: the publisher's own settings, reachable wherever
/// a mount chain named that policy.
pub trait StreamPublishSettings: Sized {
/// Publishes into `stream` rather than letting the server pick by subject.
fn stream(self, stream: impl Into<String>) -> Self;
/// Rejects the publish unless the stream's last sequence is `seq`.
fn expect_last_sequence(self, seq: u64) -> Self;
}
// Each method is one `map_publisher` call: take the policy the chain carries, set the
// option on it, hand it back. Everything else the chain named stays where it was.
impl<T: MapPublisher<Policy = StreamPublish>> StreamPublishSettings for T {
fn stream(self, stream: impl Into<String>) -> Self {
let stream = stream.into();
self.map_publisher(move |mut policy| {
policy.stream = Some(stream);
policy
})
}
fn expect_last_sequence(self, seq: u64) -> Self {
self.map_publisher(move |mut policy| {
policy.expect_last_sequence = Some(seq);
policy
})
}
}Required Associated Types§
Required Methods§
Sourcefn map_publisher(self, f: impl FnOnce(Self::Policy) -> Self::Policy) -> Self
fn map_publisher(self, f: impl FnOnce(Self::Policy) -> Self::Policy) -> Self
Replaces it with what the broker’s own settings made of it.
The replacement is the same policy type: a broker’s publisher settings are that policy’s
own fields (an exchange, a partition key, a confirm mode), while a different policy type
is a different publish mode and belongs in the .out(marker, policy) call itself.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".