Trait bencodex::codec::decode::Decode[][src]

pub trait Decode {
    fn decode(self) -> Result<BencodexValue, DecodeError>;
}
Expand description

Decode is a trait to decode a Bencodex value.

Required methods

Decodes a Bencodex value to return from this type.

If decoding succeeds, return the value inside Ok. Otherwise, return the DecodeError inside Err.

Examples

Basic usage with Vec<u8>, the default implementor which implements Decode.

use bencodex::{ Decode, BencodexValue };

let vec = vec![b'n'];
let null = vec.decode().unwrap();

assert_eq!(BencodexValue::Null(()), null);

Implementations on Foreign Types

use bencodex::{ Decode, BencodexValue };
use std::collections::BTreeMap;

let buf = b"de".to_vec();
let dictionary = buf.decode().ok().unwrap();

assert_eq!(dictionary, BencodexValue::Dictionary(BTreeMap::new()));

Implementors