Trait bencode_decoder::BElement
[−]
[src]
pub trait BElement<T> where
T: BElement<T>, { fn decode(encoded: &[u8]) -> Result<(usize, T), &'static str>; }
Trait for all bencode elements.
Provides way to decode some type of element T
, which must have trait BElement
, from
array of bytes
Examples
Simple implementation.
use bencode_decoder::BElement; struct BExample { e: i8, } impl BElement<BExample> for BExample { fn decode(encoded: &[u8]) -> Result<(usize, BExample), &'static str> { Err("No implementation, sorry") } }
Required Methods
fn decode(encoded: &[u8]) -> Result<(usize, T), &'static str>
Decodes element from array of bytes.
Returns Ok((position of last used byte in array of bytes, parsed element))
or
Err
if parse has failed.