Trait bip_bencode::BencodeConvert [] [src]

pub trait BencodeConvert {
    type Error;
    fn handle_error(&self, error: BencodeConvertError) -> Self::Error;

    fn convert_int<'a>(&self, bencode: &Bencode<'a>, error_key: &str) -> Result<i64, Self::Error> { ... }
    fn convert_bytes<'a>(&self, bencode: &Bencode<'a>, error_key: &str) -> Result<&'a [u8], Self::Error> { ... }
    fn convert_str<'a>(&self, bencode: &Bencode<'a>, error_key: &str) -> Result<&'a str, Self::Error> { ... }
    fn convert_list<'a, 'b>(&self, bencode: &'b Bencode<'a>, error_key: &str) -> Result<&'b [Bencode<'a>], Self::Error> { ... }
    fn convert_dict<'a, 'b>(&self, bencode: &'b Bencode<'a>, error_key: &str) -> Result<&'b Dictionary<'a, Bencode<'a>>, Self::Error> { ... }
    fn lookup<'a, 'b>(&self, dictionary: &'b Dictionary<'a, Bencode<'a>>, key: &str) -> Result<&'b Bencode<'a>, Self::Error> { ... }
    fn lookup_and_convert_int<'a>(&self, dictionary: &Dictionary<'a, Bencode<'a>>, key: &str) -> Result<i64, Self::Error> { ... }
    fn lookup_and_convert_bytes<'a>(&self, dictionary: &Dictionary<'a, Bencode<'a>>, key: &str) -> Result<&'a [u8], Self::Error> { ... }
    fn lookup_and_convert_str<'a>(&self, dictionary: &Dictionary<'a, Bencode<'a>>, key: &str) -> Result<&'a str, Self::Error> { ... }
    fn lookup_and_convert_list<'a: 'b, 'b>(&self, dictionary: &'b Dictionary<'a, Bencode<'a>>, key: &str) -> Result<&'b [Bencode<'a>], Self::Error> { ... }
    fn lookup_and_convert_dict<'a: 'b, 'b>(&self, dictionary: &'b Dictionary<'a, Bencode<'a>>, key: &str) -> Result<&'b Dictionary<'a, Bencode<'a>>, Self::Error> { ... }
}

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

Associated Types

type Error

Required Methods

fn handle_error(&self, error: BencodeConvertError) -> Self::Error

Convert the given conversion error into the appropriate error type.

Provided Methods

fn convert_int<'a>(&self, bencode: &Bencode<'a>, error_key: &str) -> Result<i64, Self::Error>

Attempt to convert the given bencode value into an integer.

Error key is used to generate an appropriate error message should the operation return an error.

fn convert_bytes<'a>(&self, bencode: &Bencode<'a>, error_key: &str) -> Result<&'a [u8], Self::Error>

Attempt to convert the given bencode value into bytes.

EError key is used to generate an appropriate error message should the operation return an error.

fn convert_str<'a>(&self, bencode: &Bencode<'a>, error_key: &str) -> Result<&'a str, Self::Error>

Attempt to convert the given bencode value into a UTF-8 string.

Error key is used to generate an appropriate error message should the operation return an error.

fn convert_list<'a, 'b>(&self, bencode: &'b Bencode<'a>, error_key: &str) -> Result<&'b [Bencode<'a>], Self::Error>

Attempty to convert the given bencode value into a list.

Error key is used to generate an appropriate error message should the operation return an error.

fn convert_dict<'a, 'b>(&self, bencode: &'b Bencode<'a>, error_key: &str) -> Result<&'b Dictionary<'a, Bencode<'a>>, Self::Error>

Attempt to convert the given bencode value into a dictionary.

Error key is used to generate an appropriate error message should the operation return an error.

fn lookup<'a, 'b>(&self, dictionary: &'b Dictionary<'a, Bencode<'a>>, key: &str) -> Result<&'b Bencode<'a>, Self::Error>

Look up a value in a dictionary of bencoded values using the given key.

fn lookup_and_convert_int<'a>(&self, dictionary: &Dictionary<'a, Bencode<'a>>, key: &str) -> Result<i64, Self::Error>

Combines a lookup operation on the given key with a conversion of the value, if found, to an integer.

fn lookup_and_convert_bytes<'a>(&self, dictionary: &Dictionary<'a, Bencode<'a>>, key: &str) -> Result<&'a [u8], Self::Error>

Combines a lookup operation on the given key with a conversion of the value, if found, to a series of bytes.

fn lookup_and_convert_str<'a>(&self, dictionary: &Dictionary<'a, Bencode<'a>>, key: &str) -> Result<&'a str, Self::Error>

Combines a lookup operation on the given key with a conversion of the value, if found, to a UTF-8 string.

fn lookup_and_convert_list<'a: 'b, 'b>(&self, dictionary: &'b Dictionary<'a, Bencode<'a>>, key: &str) -> Result<&'b [Bencode<'a>], Self::Error>

Combines a lookup operation on the given key with a conversion of the value, if found, to a list.

fn lookup_and_convert_dict<'a: 'b, 'b>(&self, dictionary: &'b Dictionary<'a, Bencode<'a>>, key: &str) -> Result<&'b Dictionary<'a, Bencode<'a>>, Self::Error>

Combines a lookup operation on the given key with a conversion of the value, if found, to a dictionary.

Implementors