netstring-parser
A simple, zero-copy netstring parser for Rust, designed for incremental parsing of streaming data with minimal allocations.
Features
- ✅ Zero-copy parsing for streaming I/O
- ✅ Incremental parsing of partial data
- ✅ Safe Rust (no
unsafecode) - ✅ Optional non-zero-copy mode for convenience
Zero-Copy Parsing with Streaming I/O
The parser is optimized for streaming I/O.
You can avoid unnecessary copies by using the methods available_buffer and advance to read directly into the buffer of the parser:
use ;
use NetstringParser;
available_buffer()gives you a mutable slice to write into.advance(n)informs the parser that n bytes were written.parse_next()retrieves the next complete netstring if available.
Non-Zero-Copy Parsing
If zero-copy parsing is not feasible, use the write method to copy data into the parser’s internal buffer:
use NetstringParser;
let mut parser = new;
// Imagine this data coming in via some stream in small chunks
let chunks: & = &;
for chunk in chunks
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
netstring-parser makes parsing netstrings in Rust fast, safe, and efficient. 🚀