Expand description
Library for parsing and converting bencoded data.
Examples
Decoding bencoded data:
extern crate bencode;
use std::default::Default;
use bencode::{BencodeRef, BRefAccess, BDecodeOpt};
fn main() {
let data = b"d12:lucky_numberi7ee"; // cspell:disable-line
let bencode = BencodeRef::decode(data, BDecodeOpt::default()).unwrap();
assert_eq!(7, bencode.dict().unwrap().lookup("lucky_number".as_bytes())
.unwrap().int().unwrap());
}
Encoding bencoded data:
#[macro_use]
extern crate bencode;
fn main() {
let message = (ben_map!{
"lucky_number" => ben_int!(7),
"lucky_string" => ben_bytes!("7")
}).encode();
let data = b"d12:lucky_numberi7e12:lucky_string1:7e"; // cspell:disable-line
assert_eq!(&data[..], &message[..]);
}
Modules
- Traits for extended functionality.
- Traits for implementation functionality.
Macros
- Construct
BencodeMut
bytes by supplying a type convertible toVec<u8>
. - Construct a
BencodeMut
integer by supplying ani64
. - Construct a
BencodeMut
list by supplying a list ofBencodeMut
values. - Construct a
BencodeMut
map by supplying string references as keys andBencodeMut
as values.
Structs
- Stores decoding options for modifying decode behavior.
- The Error type.
BencodeMut
object that stores references to some data.- The Error type.
BencodeRef
object that stores references to some buffer.
Enums
- The kind of an error.
- Abstract representation of a
BencodeMut
object. - The kind of an error.
- Abstract representation of a
BencodeRef
object. - Abstract representation of a
BencodeMut
object. - Abstract representation of a
BencodeRef
object.
Traits
- Trait for casting bencode objects and converting conversion errors into application specific errors.
- Trait for working with generic map data structures.
- Trait for working with generic list data structures.
- Trait for write access to some bencode type.
- Trait for read access to some bencode type.
Type Aliases
- Convenient wrapper around
std::Result
. - Convenient wrapper around
std::Result
.