stream-rs 0.1.0

Zero-dependency, spec-compliant streaming toolkit for LLM responses (SSE, incremental JSON, OpenAI/Anthropic delta accumulators).
Documentation
//! # stream-rs
//!
//! A zero-dependency, spec-compliant streaming toolkit for LLM responses.
//!
//! It gives you the low-level plumbing that sits *underneath* an LLM client —
//! none of the model, transport, or API-key concerns, just the parsing that
//! turns a raw byte stream into usable values:
//!
//! * [`sse`] — a WHATWG-compliant Server-Sent Events push parser.
//! * [`incremental_json`] — a byte-level splitter that finds complete top-level
//!   JSON values in a chunked stream (NDJSON or bare concatenation).
//! * [`accumulators`] — fold provider-specific streaming deltas
//!   ([`OpenAI`](accumulators::openai), [Anthropic](accumulators::anthropic),
//!   and [Gemini](accumulators::gemini)) back into the final message content.
//!
//! The core has **no runtime dependencies**. An optional `stream` feature adds
//! a [`futures_core::Stream`] adapter ([`stream::SseStream`]) for async byte
//! sources; enable it with `features = ["stream"]`.
//!
//! ## `no_std`
//!
//! The crate is `#![no_std]` and needs only `alloc`. The default `std` feature
//! merely adds [`std::error::Error`] impls for the error types; disable it for
//! embedded / wasm targets:
//!
//! ```toml
//! stream-rs = { version = "0.1", default-features = false }
//! ```
//!
//! ## Quick start
//!
//! ```
//! use stream_rs::sse::SseParser;
//!
//! let mut parser = SseParser::new();
//! let mut events = Vec::new();
//! parser.feed(b"data: {\"hello\":true}\n\n", &mut events);
//!
//! assert_eq!(events[0].data, "{\"hello\":true}");
//! ```

#![cfg_attr(docsrs, feature(doc_cfg))]
#![no_std]

extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

pub mod accumulators;
pub mod error;
pub mod incremental_json;
pub mod sse;

#[cfg(feature = "stream")]
#[cfg_attr(docsrs, doc(cfg(feature = "stream")))]
pub mod stream;

pub use error::{AccumulateError, MalformedJson, TruncatedJson};
pub use incremental_json::{FinishError, JsonSplitter};
pub use sse::{SseEvent, SseParser};