Trait BElement

Source
pub trait BElement<T>
where T: BElement<T>,
{ // Required method fn decode(encoded: &[u8]) -> Result<(usize, T), &'static str>; }
Expand description

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§

Source

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.

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§