pub struct EventParser { /* private fields */ }Expand description
Incremental SSE parser for Anthropic’s messages stream.
Stateful: feed bytes as they arrive, drain ready events with
next_event. Safe to call feed after every
network read of any size, including mid-event.
Implementations§
Source§impl EventParser
impl EventParser
Sourcepub fn feed(&mut self, bytes: &[u8]) -> usize
pub fn feed(&mut self, bytes: &[u8]) -> usize
Append bytes to the parser’s buffer and process any complete events.
Non-UTF-8 bytes are dropped (Anthropic’s SSE is always UTF-8 in practice). Returns the number of new events parsed and queued.
Sourcepub fn next_event(&mut self) -> Result<Option<Event>, ParseError>
pub fn next_event(&mut self) -> Result<Option<Event>, ParseError>
Pull the next ready event, or Ok(None) if the buffer is empty.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EventParser
impl RefUnwindSafe for EventParser
impl Send for EventParser
impl Sync for EventParser
impl Unpin for EventParser
impl UnsafeUnpin for EventParser
impl UnwindSafe for EventParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more