Skip to main content

SseDecoder

Struct SseDecoder 

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

Incremental Server-Sent Events decoder.

Accumulates event: and data: field lines and emits an SseEvent when a blank line terminates the record (standard SSE dispatch). Multiple data: lines within one record are joined with \n. Comment lines (those starting with :) and unknown fields are ignored. Field values have a single leading space after the colon stripped, per the SSE specification.

push does the newline framing internally via LineDecoder; callers that already have whole lines can use push_line.

Implementations§

Source§

impl SseDecoder

Source

pub fn new() -> Self

Create an empty decoder.

Source

pub fn push(&mut self, bytes: &[u8]) -> Vec<SseEvent>

Feed raw bytes; return any records completed by blank lines.

Source

pub fn push_line(&mut self, line: &str) -> Option<SseEvent>

Feed a single already-framed line (without its terminating newline). Returns an SseEvent when this line is the blank line that dispatches the accumulated record.

Source

pub fn flush(&mut self) -> Option<SseEvent>

Flush any buffered partial line and any accumulated-but-undispatched record (a stream that ended without a final blank line).

Trait Implementations§

Source§

impl Debug for SseDecoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SseDecoder

Source§

fn default() -> SseDecoder

Returns the “default value” for a type. Read more

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.