Function offseter

Source
pub(crate) fn offseter<'a>(start: &'a [u8]) -> impl Fn(&'a [u8]) -> usize + 'a
Expand description

Returns a function that converts two slices to an offset.

It takes the starting point as input and returns a function that, when given an ending point (greater than or equal to the starting point), then the corresponding pointers are subtracted and an offset relative to the starting point is returned.

This is useful as a helper function in parsing routines that use slices but want to report offsets.

ยงPanics

This may panic if the ending point is not a suffix slice of start.