multipart-async-stream
A high-performance, zero-copy streaming multipart parser for Rust.
This is a general-purpose multipart parser compatible with all RFC 2046 multipart types (form-data, byteranges, mixed, alternative, related, etc.). The parser handles boundary detection and part streaming, while you handle the type-specific semantics in your application code.
Features
- Zero-copy parsing - Uses
memchrfor efficient pattern matching - Streaming API - Process data incrementally without buffering the entire input
- Universal support - Works with all standard multipart types
Quick Start
use ;
use Bytes;
use ;
async
Important Usage Notes
You MUST consume each part's body before requesting the next part
This library uses a lending iterator pattern where each Part must be fully consumed before calling next():
- Access headers before body: Calling
part.body()consumes the part, so you must accesspart.headers()first - Consume the body completely: The body stream must be fully consumed (until it returns
None) before callingnext()again - Failure to comply: Will result in a
BodyNotConsumederror
❌ Wrong
let part = multipart.next.await?.unwrap;
let body = part.body; // Consumes the part
println!; // ERROR: part is already consumed!
✅ Right
while let Some = multipart.next.await
HTTP Range Request Example
use ;
async
Performance
- O(n) time - Single pass through the input
- O(1) space - Fixed buffer size regardless of input size
- Zero-copy - Body chunks are views into the input buffer
- memchr-optimized - Uses SIMD-accelerated pattern matching