Skip to main content

EventStreamWriter

Struct EventStreamWriter 

Source
pub struct EventStreamWriter { /* private fields */ }
Expand description

Producer helper for a streaming HTTP response — thin sugar over plain event sends to the caller’s reply route (Java EventStreamWriter).

Implementations§

Source§

impl EventStreamWriter

Source

pub fn new( platform: &Platform, reply_to: &str, correlation_id: Option<&str>, ) -> Result<Self, AppError>

Create a writer for a reply route and correlation id.

Returns HTTP-400 when the reply route is empty — a streaming producer without a reply address has nowhere to stream.

Source

pub fn from_request( platform: &Platform, request: &EventEnvelope, ) -> Result<Self, AppError>

Create a writer from the incoming request envelope (the usual form for an interceptor function).

Source

pub fn first(&mut self, status: i32, content_type: &str) -> &mut Self

Optional head control carried by the first outgoing event: response status and content type. Later events cannot change the head.

Source

pub fn first_with_ttl( &mut self, status: i32, content_type: &str, ttl_seconds: u64, ) -> &mut Self

Head control plus an idle-allowance override in seconds between segments (rides the first event as the x-ttl envelope header).

Source

pub async fn write<T: Serialize>(&mut self, segment: T) -> Result<(), AppError>

Send one data segment (String, bytes or map — any serializable body).

Source

pub async fn write_named<T: Serialize>( &mut self, event_name: &str, segment: T, ) -> Result<(), AppError>

Send one named segment — the name maps to the SSE event: field.

Source

pub async fn close(&mut self) -> Result<(), AppError>

Declare end of transmission.

Source

pub async fn close_with<T: Serialize>( &mut self, metadata: T, ) -> Result<(), AppError>

Declare end of transmission with trailing metadata (rendered as the terminal SSE event’s data; ignored in chunked mode).

Source

pub async fn fail(&mut self, error: &AppError) -> Result<(), AppError>

Declare an in-band failure and end the stream.

Source

pub fn is_closed(&self) -> bool

True when the stream has been closed or failed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V