Skip to main content

ProducerExt

Trait ProducerExt 

Source
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 + OutgoingMessage to a new shared crate that both magnetar and magnetar-runtime-tokio depend on. Cleanest layering but adds a crate to publish.
  • Move MessageBuilder down into magnetar-runtime-tokio. Inverts the workspace dep graph and ties MessageBuilder to the tokio engine specifically — bad fit because the V5 surface and any future engine-generic producer surface want MessageBuilder at 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§

Source

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".

Implementations on Foreign Types§

Source§

impl ProducerExt for Producer

Implementors§