| Crates.io | bencode-minimal |
| lib.rs | bencode-minimal |
| version | 0.1.0 |
| created_at | 2025-11-03 21:35:18.404345+00 |
| updated_at | 2025-11-03 21:35:18.404345+00 |
| description | A Bencode library depending only on the Rust standard library. |
| homepage | https://github.com/lpeterse/bencode-minimal |
| repository | https://github.com/lpeterse/bencode-minimal |
| max_upload_size | |
| id | 1915310 |
| size | 28,628 |
A Bencode library depending only on the Rust standard library.
use bencode_minimal::*;
let v1 = dict! {
"name" => str!("John"),
"age" => int!(42),
"friends" => list![
str!("Alice"),
dict! {
"name" => str!("Bob"),
"data" => str!(vec![48u8, 49, 50]),
}
]
};
let bin = v1.encode();
assert_eq!(&bin, b"d3:agei42e7:friendsl5:Aliced4:data3:0124:name3:Bobee4:name4:Johne");
let v2 = Value::decode(&bin, 10).unwrap();
println!("{:#?}", v2);
Output:
{
"age": 42,
"friends": [
"Alice",
{
"data": "012",
"name": "Bob",
},
],
"name": "John",
}
Dictionaries are always encoded with keys in ascending order as the format mandates. When it comes to decoding, any order is accepted. This avoids headache when dealing with non-compliant peers.
Duplicate keys are forbidden for security reasons, though.
Every instance of a Bencode value can be encoded. No errors to handle in this case.
OptionalThe decoder makes no attempt to report any details about failures or the failure location. This is for simplicity: This is a decoder for a strict and simple format and not a parser. In most circumstances this information would not be looked at anyway. If you need this information for debugging, use something else.