pub trait ProducerExt {
// Required method
fn new_message(&self) -> MessageBuilder<'_>;
}Expand description
Extension trait that gives magnetar_runtime_tokio::Producer the Java-symmetric
producer.new_message().key(..).value(..).send().await entry point.
Bring it into scope with use magnetar::ProducerExt;.
§Why an extension trait
The trait exists to satisfy Rust’s orphan rule: MessageBuilder
lives in this façade crate (magnetar), and Producer lives in
magnetar-runtime-tokio (a downstream crate from magnetar’s
perspective in the workspace dep graph). Neither side can directly
impl MessageBuilder<'_> against the foreign Producer without
the trait indirection.
Two alternatives were considered and rejected:
- Move
MessageBuilder+OutgoingMessageto a new shared crate that bothmagnetarandmagnetar-runtime-tokiodepend on. Cleanest layering but adds a crate to publish. - Move
MessageBuilderdown intomagnetar-runtime-tokio. Inverts the workspace dep graph and tiesMessageBuilderto the tokio engine specifically — bad fit because the V5 surface and any future engine-generic producer surface wantMessageBuilderat the façade tier.
Chosen path: accept the trait as a zero-cost layering artefact.
The single-impl trait is the canonical Rust workaround for this
shape; bringing it into scope with use magnetar::ProducerExt; is
a one-line cost at every call site, and the trait + impl produce
no runtime overhead.
Required Methods§
Sourcefn new_message(&self) -> MessageBuilder<'_>
fn new_message(&self) -> MessageBuilder<'_>
Start a new OutgoingMessage bound to this producer. Chain the same setters as
OutgoingMessage (OutgoingMessage::key, OutgoingMessage::value,
OutgoingMessage::event_time_ms, etc.) and finish with .send().await.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".