Skip to main content

EventStreamFormatter

Trait EventStreamFormatter 

Source
pub trait EventStreamFormatter {
    // Required methods
    fn content_type(&self) -> &'static str;
    fn encode(&self, event: &Event) -> Result<Vec<u8>>;
}
Available on crate features protobuf or sse only.
Expand description

Turns events into the bytes a transport puts on the wire.

Object-safe, so a server can pick a formatter once per connection and store it as Box<dyn EventStreamFormatter>.

Required Methods§

Source

fn content_type(&self) -> &'static str

The Content-Type to answer with.

Source

fn encode(&self, event: &Event) -> Result<Vec<u8>>

Encodes one event, framing included.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl EventStreamFormatter for ProtobufFormatter

Available on crate feature protobuf only.
Source§

impl EventStreamFormatter for SseFormatter

Available on crate feature sse only.