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 to Vec<u8>.
  • Construct a BencodeMut integer by supplying an i64.
  • Construct a BencodeMut list by supplying a list of BencodeMut values.
  • Construct a BencodeMut map by supplying string references as keys and BencodeMut as values.

Structs

Enums

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