[][src]Enum sveppa_bencode::Bencode

pub enum Bencode {
    Value(Vec<u8>),
    List(Vec<Bencode>),
    Dict(HashMap<Vec<u8>, Bencode>),
}

A nested enum containing the parsed Bencode file structure.

Variants

Value(Vec<u8>)

A value. (or a 'leaf' in tree terminology) which can be converted into a value with any of: as_string(), as_bytes(), or as_usize().

Possible options:

  • An Integer. eg: i123e. indicated by i and terminated by e.
  • A ByteString. eg: 3:cat. stars with an integer length, followed by : as a separator, then the bytes.
List(Vec<Bencode>)

A list of Bencode structs which can be destructured into a Vec with as_vec().

A map of bencoded values. All keys are Vec, and values are nested Bencode structs. This can be destructured with as_map().

Implementations

impl Bencode[src]

pub fn as_usize(&self) -> Result<usize, BencodeParserError>[src]

Attempt to parse a Bencode::Value variant into a usize.

Can return:

  • InvalidVariantMethod, if called on any of Bencode::{List, Dict}.
  • InvalidUTF8String, if the bytes cannot be parsed as a UTF8, ASCII string.
  • InvalidASCIIInteger, if the ASCII bytes aren't a valid base 10 number.

pub fn as_string(&self) -> Result<String, BencodeParserError>[src]

Attempt to parse a Bencode::Value variant into a String.

Can return:

  • InvalidVariantMethod, if called on any of Bencode::{List, Dict}.
  • InvalidUTF8String, if the bytes cannot be parsed as a UTF8, ASCII string.

pub fn as_bytes(&self) -> Result<&Vec<u8>, BencodeParserError>[src]

Destructures a Bencode::Value into a Vec<u8>. This method will always succeed if applied to a Bencode::Value.

Can return:

  • InvalidVariantMethod, if called on any of Bencode::{List, Dict}.

pub fn as_vec(&self) -> Result<&Vec<Bencode>, BencodeParserError>[src]

Attempt to parse a Bencode::List into a Vec<Bencode>. This method will always succeed if applied to a Bencode::List.

Can return:

  • InvalidVariantMethod, if called on any of Bencode::{Value, Dict}.

pub fn as_map(&self) -> Result<&HashMap<Vec<u8>, Bencode>, BencodeParserError>[src]

Attempt to parse a Bencode::Dict into a HashMap<Vec<u8>, Bencode>. This method will always succeed if applied to a Bencode::Dict.

Can return:

  • InvalidVariantMethod, if called on any of Bencode::{Value, List}.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.