pub struct StreamParser { /* private fields */ }Expand description
Parser for streaming SSE responses
Handles incremental parsing of tool calls from Server-Sent Events (SSE) streams. Accumulates partial data and emits deltas as they arrive.
§Example
ⓘ
let mut parser = StreamParser::new(Provider::Anthropic);
// Process each SSE chunk
for chunk in sse_stream {
if let Some(delta) = parser.parse_chunk(&chunk)? {
match delta {
ToolDelta::Start { name, .. } => println!("Starting: {}", name),
ToolDelta::Arguments { delta } => print!("{}", delta),
ToolDelta::End => println!("\nDone!"),
}
}
}
// Get the complete tool call
let tool_call = parser.finalize()?;Implementations§
Source§impl StreamParser
impl StreamParser
Sourcepub fn new(provider: Provider) -> Self
pub fn new(provider: Provider) -> Self
Create a new streaming parser for the specified provider
Auto Trait Implementations§
impl Freeze for StreamParser
impl RefUnwindSafe for StreamParser
impl Send for StreamParser
impl Sync for StreamParser
impl Unpin for StreamParser
impl UnwindSafe for StreamParser
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