bencode
Super-fast bencode parser written in Rust.
Quick start
let bs = "d4:listli1ei2ee4:ping4:ponge".as_bytes; // Bencode data to parse.
let reader = from_bytes;
let mut root = reader.root; // Get root object
// Iterate through list of numbers
for item in root.get.iter_numbers
// Get byte value from dict
let val = root.get.bytes.unwrap;
// The parser is fault tolerant.
let val = root.get.get.bytes; // --> Returns None.
Performance tip
This library is especially fast, if you query dict entries alphabetically.
root.get.bytes.unwrap; // Query bytes
root.get.number.unwrap; // Query number (isize)
root.get.get.iter_bytes;
// Caching is also useful.
let c = root.get;
c.get;
c.get;
// ...
Comments
- We could make this library zero-alloction, but we need to work around Rust's ownership model.
- This is my first Rust project, so feel free to comment on this.