Trait bip_bencode::BencodeConvert
[−]
[src]
pub trait BencodeConvert { type Error; fn handle_error(&self, error: BencodeConvertError) -> Self::Error; fn convert_int<'a, E>(&self,
bencode: &Bencode<'a>,
error_key: E)
-> Result<i64, Self::Error> where E: AsRef<[u8]> { ... } fn convert_bytes<'a, E>(&self,
bencode: &Bencode<'a>,
error_key: E)
-> Result<&'a [u8], Self::Error> where E: AsRef<[u8]> { ... } fn convert_str<'a, E>(&self,
bencode: &Bencode<'a>,
error_key: E)
-> Result<&'a str, Self::Error> where E: AsRef<[u8]> { ... } fn convert_list<'a, 'b, E>(&self,
bencode: &'b Bencode<'a>,
error_key: E)
-> Result<&'b [Bencode<'a>], Self::Error> where E: AsRef<[u8]> { ... } fn convert_dict<'a, 'b, E>(&self,
bencode: &'b Bencode<'a>,
error_key: E)
-> Result<&'b Dictionary<'a, Bencode<'a>>, Self::Error> where E: AsRef<[u8]> { ... } fn lookup<'a, 'b, K>(&self,
dictionary: &'b Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'b Bencode<'a>, Self::Error> where K: AsRef<[u8]> { ... } fn lookup_and_convert_int<'a, K>(&self,
dictionary: &Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<i64, Self::Error> where K: AsRef<[u8]> { ... } fn lookup_and_convert_bytes<'a, K>(&self,
dictionary: &Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'a [u8], Self::Error> where K: AsRef<[u8]> { ... } fn lookup_and_convert_str<'a, K>(&self,
dictionary: &Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'a str, Self::Error> where K: AsRef<[u8]> { ... } fn lookup_and_convert_list<'a: 'b, 'b, K>(&self,
dictionary: &'b Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'b [Bencode<'a>], Self::Error> where K: AsRef<[u8]> { ... } fn lookup_and_convert_dict<'a: 'b, 'b, K>(&self,
dictionary: &'b Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'b Dictionary<'a, Bencode<'a>>, Self::Error> where K: AsRef<[u8]> { ... } }
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, E>(&self,
bencode: &Bencode<'a>,
error_key: E)
-> Result<i64, Self::Error> where E: AsRef<[u8]>
bencode: &Bencode<'a>,
error_key: E)
-> Result<i64, Self::Error> where 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.
fn convert_bytes<'a, E>(&self,
bencode: &Bencode<'a>,
error_key: E)
-> Result<&'a [u8], Self::Error> where E: AsRef<[u8]>
bencode: &Bencode<'a>,
error_key: E)
-> Result<&'a [u8], Self::Error> where 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.
fn convert_str<'a, E>(&self,
bencode: &Bencode<'a>,
error_key: E)
-> Result<&'a str, Self::Error> where E: AsRef<[u8]>
bencode: &Bencode<'a>,
error_key: E)
-> Result<&'a str, Self::Error> where 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.
fn convert_list<'a, 'b, E>(&self,
bencode: &'b Bencode<'a>,
error_key: E)
-> Result<&'b [Bencode<'a>], Self::Error> where E: AsRef<[u8]>
bencode: &'b Bencode<'a>,
error_key: E)
-> Result<&'b [Bencode<'a>], Self::Error> where E: AsRef<[u8]>
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, E>(&self,
bencode: &'b Bencode<'a>,
error_key: E)
-> Result<&'b Dictionary<'a, Bencode<'a>>, Self::Error> where E: AsRef<[u8]>
bencode: &'b Bencode<'a>,
error_key: E)
-> Result<&'b Dictionary<'a, Bencode<'a>>, Self::Error> where 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.
fn lookup<'a, 'b, K>(&self,
dictionary: &'b Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'b Bencode<'a>, Self::Error> where K: AsRef<[u8]>
dictionary: &'b Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'b Bencode<'a>, Self::Error> where K: AsRef<[u8]>
Look up a value in a dictionary of bencoded values using the given key.
fn lookup_and_convert_int<'a, K>(&self,
dictionary: &Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<i64, Self::Error> where K: AsRef<[u8]>
dictionary: &Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<i64, Self::Error> where K: AsRef<[u8]>
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, K>(&self,
dictionary: &Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'a [u8], Self::Error> where K: AsRef<[u8]>
dictionary: &Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'a [u8], Self::Error> where K: AsRef<[u8]>
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, K>(&self,
dictionary: &Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'a str, Self::Error> where K: AsRef<[u8]>
dictionary: &Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'a str, Self::Error> where K: AsRef<[u8]>
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, K>(&self,
dictionary: &'b Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'b [Bencode<'a>], Self::Error> where K: AsRef<[u8]>
dictionary: &'b Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'b [Bencode<'a>], Self::Error> where K: AsRef<[u8]>
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, K>(&self,
dictionary: &'b Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'b Dictionary<'a, Bencode<'a>>, Self::Error> where K: AsRef<[u8]>
dictionary: &'b Dictionary<'a, Bencode<'a>>,
key: K)
-> Result<&'b Dictionary<'a, Bencode<'a>>, Self::Error> where K: AsRef<[u8]>
Combines a lookup operation on the given key with a conversion of the value, if found, to a dictionary.