Trait Decode

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

Decode is a trait to decode a Bencodex value.

Required Methods§

Source

fn decode(self) -> Result<BencodexValue, DecodeError>

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§

Source§

impl Decode for Vec<u8>

Source§

fn decode(self) -> Result<BencodexValue, DecodeError>

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§