Enum lava_torrent::bencode::BencodeElem [] [src]

pub enum BencodeElem {
    String(String),
    Bytes(Vec<u8>),
    Integer(i64),
    List(Vec<BencodeElem>),
    Dictionary(HashMap<String, BencodeElem>),
}

Represent a single bencode element.

There are 4 variants in the spec, but this enum has 5 variants. The extra variant is Bytes (a sequence of bytes that does not represent a valid utf8 string, e.g. a SHA1 block hash), which is considered to be the same as String in the spec. But they are best treated differently in actual implementations to make things easier.

Note that the Integer variant here uses i64 explicitly instead of using a type alias like Integer. The reasoning behind this is that if you have to handle bencode directly then what you are doing is relatively low-level. In this case, exposing the underlying type might actually be better.

Variants

Methods

impl BencodeElem
[src]

[src]

Parse bytes and return all BencodeElem found.

If bytes is empty, then Ok(vec) will be returned, but vec would be empty as well.

If bytes contains any malformed bencode, or if any other error is encountered (e.g. IOError), then Err(error) will be returned.

[src]

Parse the content of the file at path and return all BencodeElem found.

If the file at path is empty, then Ok(vec) will be returned, but vec would be empty as well.

If the file at path contains any malformed bencode, or if any other error is encountered (e.g. IOError), then Err(error) will be returned.

impl BencodeElem
[src]

[src]

Encode self and write the result to dst.

[src]

Encode self and write the result to path.

path must be the path to a file.

"This function will create a file if it does not exist, and will truncate it if it does."

[src]

Encode self and return the result in a Vec.

Trait Implementations

impl Clone for BencodeElem
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for BencodeElem
[src]

[src]

Formats the value using the given formatter. Read more

impl Eq for BencodeElem
[src]

impl PartialEq for BencodeElem
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl From<u8> for BencodeElem
[src]

[src]

Performs the conversion.

impl From<u16> for BencodeElem
[src]

[src]

Performs the conversion.

impl From<u32> for BencodeElem
[src]

[src]

Performs the conversion.

impl From<i8> for BencodeElem
[src]

[src]

Performs the conversion.

impl From<i16> for BencodeElem
[src]

[src]

Performs the conversion.

impl From<i32> for BencodeElem
[src]

[src]

Performs the conversion.

impl From<i64> for BencodeElem
[src]

[src]

Performs the conversion.

impl<'a> From<&'a str> for BencodeElem
[src]

[src]

Performs the conversion.

impl From<String> for BencodeElem
[src]

[src]

Performs the conversion.

impl<'a> From<&'a [u8]> for BencodeElem
[src]

[src]

Performs the conversion.

impl From<Vec<u8>> for BencodeElem
[src]

[src]

Performs the conversion.

impl Display for BencodeElem
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for BencodeElem

impl Sync for BencodeElem