bip_bencode 0.2.0

Efficient decoding and encoding for bencode

Crate bip_bencode [] [src]

Library for parsing and converting bencoded data.

Examples

Decoding bencoded data:

    extern crate bip_bencode;

    use bip_bencode::{Bencode};

    fn main() {
        let data = b"d12:lucky_numberi7ee";
        let bencode = Bencode::decode(data).unwrap();

        assert_eq!(7, bencode.dict().unwrap().lookup("lucky_number".as_bytes())
            .unwrap().int().unwrap());
    }

Encoding bencoded data:

    #[macro_use]
    extern crate bip_bencode;

    use bip_bencode::{Bencode};

    fn main() {
        let message = (ben_map!{
            "lucky_number" => ben_int!(7)
        }).encode();

        assert_eq!(&b"d12:lucky_numberi7ee"[..], &message[..]);
    }

Macros

ben_bytes

Construct Bencode bytes by supplying a type convertible to Vec<u8>.

ben_int

Construct a Bencode integer by supplying an i64.

ben_list

Construct a Bencode list by supplying a list of Bencode values.

ben_map

Construct a Bencode map by supplying string references as keys and Bencode as values.

Structs

BencodeConvertError

The Error type.

BencodeParseError

The Error type.

Enums

Bencode

Bencode object that holds references to the underlying data.

BencodeConvertErrorKind

The kind of an error.

BencodeKind

Abstract representation of a Bencode object.

BencodeParseErrorKind

The kind of an error.

Traits

BencodeConvert

Trait for casting bencode objects and converting conversion errors into application specific errors.

Dictionary

Trait for working with generic map data structures.

Type Definitions

BencodeConvertResult

Convenient wrapper around std::Result.

BencodeParseResult

Convenient wrapper around std::Result.