Skip to main content

ParseHelper

Trait ParseHelper 

Source
pub trait ParseHelper: AsRef<[u8]> {
    // Provided methods
    fn take_until(&self, pattern: &[u8]) -> Result<(&[u8], &[u8]), ()> { ... }
    fn take_until_err<E: Debug>(
        &self,
        pattern: &[u8],
        err: E,
    ) -> Result<(&[u8], &[u8]), E> { ... }
    fn take_exact(&self, count: usize) -> Result<(&[u8], &[u8]), ()> { ... }
    fn take_exact_err<E: Debug>(
        &self,
        count: usize,
        err: E,
    ) -> Result<(&[u8], &[u8]), E> { ... }
    fn take_expect(&self, pattern: &[u8]) -> Result<(&[u8], &[u8]), &[u8]> { ... }
    fn take_expect_err<E: Debug>(
        &self,
        pattern: &[u8],
        err: E,
    ) -> Result<(&[u8], &[u8]), E> { ... }
    fn maybe_expect(&self, pattern: &[u8]) -> (Option<&[u8]>, &[u8]) { ... }
    fn take_smallest_err<E: Debug, F: Fn(&[u8]) -> bool>(
        &self,
        f: F,
        min_size: usize,
        err: E,
    ) -> Result<(&[u8], &[u8]), E> { ... }
    fn take_largest_err<E: Debug, F: Fn(&[u8]) -> bool>(
        &self,
        f: F,
        min_size: usize,
        err: E,
    ) -> Result<(&[u8], &[u8]), E> { ... }
}
Expand description

A trait that is implemented for everything that can be a sequence of bytes

Provided Methods§

Source

fn take_until(&self, pattern: &[u8]) -> Result<(&[u8], &[u8]), ()>

Skips prefix of slice until sequence is found

Source

fn take_until_err<E: Debug>( &self, pattern: &[u8], err: E, ) -> Result<(&[u8], &[u8]), E>

Skips prefix of slice until sequence is found and returns provided error if not

Source

fn take_exact(&self, count: usize) -> Result<(&[u8], &[u8]), ()>

Returns a slice of exact length

Source

fn take_exact_err<E: Debug>( &self, count: usize, err: E, ) -> Result<(&[u8], &[u8]), E>

Returns a slice of exact length and returns provided error if not

Source

fn take_expect(&self, pattern: &[u8]) -> Result<(&[u8], &[u8]), &[u8]>

Returns a slice of the provided pattern and the rest of the slice

Source

fn take_expect_err<E: Debug>( &self, pattern: &[u8], err: E, ) -> Result<(&[u8], &[u8]), E>

Returns a slice of the provided pattern and the rest of the slice and returns provided error if not

Source

fn maybe_expect(&self, pattern: &[u8]) -> (Option<&[u8]>, &[u8])

If the next pattern is optional, it may return it, otherwise it returns the original slice

Source

fn take_smallest_err<E: Debug, F: Fn(&[u8]) -> bool>( &self, f: F, min_size: usize, err: E, ) -> Result<(&[u8], &[u8]), E>

Returns the smallest first slice found from the start that matches the condition i.e. it runs the function until the first time it is true

Source

fn take_largest_err<E: Debug, F: Fn(&[u8]) -> bool>( &self, f: F, min_size: usize, err: E, ) -> Result<(&[u8], &[u8]), E>

Returns the largest slice found from the start that matches the condition. i.e. it runs the function until the last time it is true

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 ParseHelper for &[u8]

Source§

impl ParseHelper for &str

Source§

impl ParseHelper for Vec<u8>

Source§

impl ParseHelper for [u8]

Implementors§