Skip to main content

EncodingShape

Trait EncodingShape 

Source
pub trait EncodingShape {
    type State: Clone + Eq + Hash + Debug + 'static;

    // Required methods
    fn start() -> Self::State;
    fn step(state: &Self::State, byte: u8) -> Option<Self::State>;
    fn accepts(state: &Self::State) -> bool;
}
Expand description

The byte strings that crate::Deserializable::deserialize reads in full, as a finite automaton over bytes.

Encodings must be prefix-free, as self-delimiting encodings are: no accepted string continues into another. Checking a set of encodings costs time proportional to the number of distinct states reached, so State should take few values.

Required Associated Types§

Source

type State: Clone + Eq + Hash + Debug + 'static

A position in the automaton.

Required Methods§

Source

fn start() -> Self::State

The state before any byte is read.

Source

fn step(state: &Self::State, byte: u8) -> Option<Self::State>

The state after reading byte, or None if no encoding continues so.

Source

fn accepts(state: &Self::State) -> bool

Whether the bytes read so far are a complete encoding.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl EncodingShape for ()

Source§

type State = <[u8; 0] as EncodingShape>::State

Source§

fn start() -> Self::State

Source§

fn step(state: &Self::State, byte: u8) -> Option<Self::State>

Source§

fn accepts(state: &Self::State) -> bool

Source§

impl EncodingShape for bool

Source§

type State = bool

Source§

fn start() -> bool

Source§

fn step(done: &bool, byte: u8) -> Option<bool>

Source§

fn accepts(done: &bool) -> bool

Source§

impl EncodingShape for i8

Source§

type State = <[u8; 1] as EncodingShape>::State

Source§

fn start() -> Self::State

Source§

fn step(state: &Self::State, byte: u8) -> Option<Self::State>

Source§

fn accepts(state: &Self::State) -> bool

Source§

impl EncodingShape for i16

Source§

type State = <[u8; 2] as EncodingShape>::State

Source§

fn start() -> Self::State

Source§

fn step(state: &Self::State, byte: u8) -> Option<Self::State>

Source§

fn accepts(state: &Self::State) -> bool

Source§

impl EncodingShape for i32

Source§

type State = <[u8; 4] as EncodingShape>::State

Source§

fn start() -> Self::State

Source§

fn step(state: &Self::State, byte: u8) -> Option<Self::State>

Source§

fn accepts(state: &Self::State) -> bool

Source§

impl EncodingShape for i64

Source§

type State = <[u8; 8] as EncodingShape>::State

Source§

fn start() -> Self::State

Source§

fn step(state: &Self::State, byte: u8) -> Option<Self::State>

Source§

fn accepts(state: &Self::State) -> bool

Source§

impl EncodingShape for i128

Source§

type State = <[u8; 16] as EncodingShape>::State

Source§

fn start() -> Self::State

Source§

fn step(state: &Self::State, byte: u8) -> Option<Self::State>

Source§

fn accepts(state: &Self::State) -> bool

Source§

impl EncodingShape for u8

Source§

type State = <[u8; 1] as EncodingShape>::State

Source§

fn start() -> Self::State

Source§

fn step(state: &Self::State, byte: u8) -> Option<Self::State>

Source§

fn accepts(state: &Self::State) -> bool

Source§

impl EncodingShape for u16

Source§

type State = <[u8; 2] as EncodingShape>::State

Source§

fn start() -> Self::State

Source§

fn step(state: &Self::State, byte: u8) -> Option<Self::State>

Source§

fn accepts(state: &Self::State) -> bool

Source§

impl EncodingShape for u32

Source§

impl EncodingShape for u64

Source§

impl EncodingShape for u128

Source§

impl<A: EncodingShape, B: EncodingShape> EncodingShape for (A, B)

Source§

type State = SeqState<<A as EncodingShape>::State, <B as EncodingShape>::State>

Source§

fn start() -> Self::State

Source§

fn step(state: &Self::State, byte: u8) -> Option<Self::State>

Source§

fn accepts(state: &Self::State) -> bool

Source§

impl<const N: usize> EncodingShape for [u8; N]

Implementors§