Trait Engine

Source
pub trait Engine {
    type Digest;

    // Required methods
    fn roll_byte(&mut self, byte: u8);
    fn digest(&self) -> Self::Digest;
    fn reset(&mut self);

    // Provided methods
    fn roll(&mut self, buf: &[u8]) { ... }
    fn find_chunk_edge_cond<F>(
        &mut self,
        buf: &[u8],
        cond: F,
    ) -> Option<(usize, Self::Digest)>
       where F: Fn(&Self) -> bool { ... }
}
Expand description

Rolling sum engine trait

Required Associated Types§

Required Methods§

Source

fn roll_byte(&mut self, byte: u8)

Roll over one byte

Source

fn digest(&self) -> Self::Digest

Return current rolling sum digest

Source

fn reset(&mut self)

Resets the internal state

Provided Methods§

Source

fn roll(&mut self, buf: &[u8])

Roll over a slice of bytes

Source

fn find_chunk_edge_cond<F>( &mut self, buf: &[u8], cond: F, ) -> Option<(usize, Self::Digest)>
where F: Fn(&Self) -> bool,

Find the end of the chunk.

Feed engine bytes from buf and stop when chunk split was found.

Use cond function as chunk split condition.

When edge is find, state of self is reset, using reset() method.

Returns:

  • None - no chunk split was found
  • Some - offset of the first unconsumed byte of buf and the digest of the whole chunk. offset == buf.len() if the chunk ended right after the whole buf.

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§