BConvert

Trait BConvert 

Source
pub trait BConvert {
    type Error;

    // Required method
    fn handle_error(&self, error: BencodeConvertError) -> Self::Error;

    // Provided methods
    fn convert_int<B, E>(
        &self,
        bencode: B,
        error_key: E,
    ) -> Result<i64, Self::Error>
       where B: BRefAccess,
             E: AsRef<[u8]> { ... }
    fn convert_bytes<'a, B, E>(
        &self,
        bencode: &'a B,
        error_key: E,
    ) -> Result<&'a [u8], Self::Error>
       where B: BRefAccess,
             E: AsRef<[u8]> { ... }
    fn convert_str<'a, B, E>(
        &self,
        bencode: &'a B,
        error_key: E,
    ) -> Result<&'a str, Self::Error>
       where B: BRefAccess,
             E: AsRef<[u8]> { ... }
    fn convert_list<'a, B, E>(
        &self,
        bencode: &'a B,
        error_key: E,
    ) -> Result<&'a dyn BListAccess<B::BType>, Self::Error>
       where B: BRefAccess,
             E: AsRef<[u8]> { ... }
    fn convert_dict<'a, B, E>(
        &self,
        bencode: &'a B,
        error_key: E,
    ) -> Result<&'a dyn BDictAccess<B::BKey, B::BType>, Self::Error>
       where B: BRefAccess,
             E: AsRef<[u8]> { ... }
    fn lookup<'a, B, K1, K2>(
        &self,
        dictionary: &'a dyn BDictAccess<K1, B>,
        key: K2,
    ) -> Result<&'a B, Self::Error>
       where B: BRefAccess,
             K2: AsRef<[u8]> { ... }
    fn lookup_and_convert_int<B, K1, K2>(
        &self,
        dictionary: &dyn BDictAccess<K1, B>,
        key: K2,
    ) -> Result<i64, Self::Error>
       where B: BRefAccess,
             K2: AsRef<[u8]> { ... }
    fn lookup_and_convert_bytes<'a, B, K1, K2>(
        &self,
        dictionary: &'a dyn BDictAccess<K1, B>,
        key: K2,
    ) -> Result<&'a [u8], Self::Error>
       where B: BRefAccess,
             K2: AsRef<[u8]> { ... }
    fn lookup_and_convert_str<'a, B, K1, K2>(
        &self,
        dictionary: &'a dyn BDictAccess<K1, B>,
        key: K2,
    ) -> Result<&'a str, Self::Error>
       where B: BRefAccess,
             K2: AsRef<[u8]> { ... }
    fn lookup_and_convert_list<'a, B, K1, K2>(
        &self,
        dictionary: &'a dyn BDictAccess<K1, B>,
        key: K2,
    ) -> Result<&'a dyn BListAccess<B::BType>, Self::Error>
       where B: BRefAccess,
             K2: AsRef<[u8]> { ... }
    fn lookup_and_convert_dict<'a, B, K1, K2>(
        &self,
        dictionary: &'a dyn BDictAccess<K1, B>,
        key: K2,
    ) -> Result<&'a dyn BDictAccess<B::BKey, B::BType>, Self::Error>
       where B: BRefAccess,
             K2: AsRef<[u8]> { ... }
}
Expand description

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

Required Associated Types§

Required Methods§

Source

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

Convert the given conversion error into the appropriate error type.

Provided Methods§

Source

fn convert_int<B, E>( &self, bencode: B, error_key: E, ) -> Result<i64, Self::Error>
where B: BRefAccess, E: AsRef<[u8]>,

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.

Source

fn convert_bytes<'a, B, E>( &self, bencode: &'a B, error_key: E, ) -> Result<&'a [u8], Self::Error>
where B: BRefAccess, E: AsRef<[u8]>,

Attempt to convert the given bencode value into bytes.

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

Source

fn convert_str<'a, B, E>( &self, bencode: &'a B, error_key: E, ) -> Result<&'a str, Self::Error>
where B: BRefAccess, E: AsRef<[u8]>,

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.

Source

fn convert_list<'a, B, E>( &self, bencode: &'a B, error_key: E, ) -> Result<&'a dyn BListAccess<B::BType>, Self::Error>
where B: BRefAccess, E: AsRef<[u8]>,

Attempt 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.

Source

fn convert_dict<'a, B, E>( &self, bencode: &'a B, error_key: E, ) -> Result<&'a dyn BDictAccess<B::BKey, B::BType>, Self::Error>
where B: BRefAccess, E: AsRef<[u8]>,

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.

Source

fn lookup<'a, B, K1, K2>( &self, dictionary: &'a dyn BDictAccess<K1, B>, key: K2, ) -> Result<&'a B, Self::Error>
where B: BRefAccess, K2: AsRef<[u8]>,

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

Source

fn lookup_and_convert_int<B, K1, K2>( &self, dictionary: &dyn BDictAccess<K1, B>, key: K2, ) -> Result<i64, Self::Error>
where B: BRefAccess, K2: AsRef<[u8]>,

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

Source

fn lookup_and_convert_bytes<'a, B, K1, K2>( &self, dictionary: &'a dyn BDictAccess<K1, B>, key: K2, ) -> Result<&'a [u8], Self::Error>
where B: BRefAccess, K2: AsRef<[u8]>,

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

Source

fn lookup_and_convert_str<'a, B, K1, K2>( &self, dictionary: &'a dyn BDictAccess<K1, B>, key: K2, ) -> Result<&'a str, Self::Error>
where B: BRefAccess, K2: AsRef<[u8]>,

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

Source

fn lookup_and_convert_list<'a, B, K1, K2>( &self, dictionary: &'a dyn BDictAccess<K1, B>, key: K2, ) -> Result<&'a dyn BListAccess<B::BType>, Self::Error>
where B: BRefAccess, K2: AsRef<[u8]>,

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

Source

fn lookup_and_convert_dict<'a, B, K1, K2>( &self, dictionary: &'a dyn BDictAccess<K1, B>, key: K2, ) -> Result<&'a dyn BDictAccess<B::BKey, B::BType>, Self::Error>
where B: BRefAccess, K2: AsRef<[u8]>,

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§