pub struct PayloadParts { /* private fields */ }Expand description
Zero-copy payload splitter.
Splits a Bytes payload by a delimiter and provides access to individual parts
as slices into the original payload. No allocations occur during splitting.
Supports both eager splitting (via split / split_with_finder) and
demand-driven lazy splitting (via new_lazy + ensure).
Implementations§
Source§impl PayloadParts
impl PayloadParts
Sourcepub fn split(payload: Bytes, delimiter: &[u8]) -> Self
pub fn split(payload: Bytes, delimiter: &[u8]) -> Self
Split a payload by the given delimiter.
§Arguments
payload- The payload to splitdelimiter- The delimiter bytes (e.g.,b";;;")
§Returns
A PayloadParts instance with zero-copy access to each part.
§Performance
- O(n) scan with SIMD-accelerated delimiter search
- Zero heap allocations
- Parts are slices into the original Bytes
Sourcepub fn split_with_finder(
payload: Bytes,
finder: &Finder<'_>,
delim_len: usize,
) -> Self
pub fn split_with_finder( payload: Bytes, finder: &Finder<'_>, delim_len: usize, ) -> Self
Split a payload using a pre-built Finder.
This avoids rebuilding the SIMD searcher on every call.
§Arguments
payload- The payload to splitfinder- Pre-built delimiter finderdelim_len- Length of the delimiter in bytes
Sourcepub fn new_lazy(payload: Bytes) -> Self
pub fn new_lazy(payload: Bytes) -> Self
Create a lazy payload splitter that scans delimiters on demand.
No scanning happens until ensure() is called.
Sourcepub fn ensure(&mut self, index: usize, finder: &Finder<'_>, delim_len: usize)
pub fn ensure(&mut self, index: usize, finder: &Finder<'_>, delim_len: usize)
Ensure that part index is available by scanning delimiters incrementally.
After this call, self.get(index) returns the correct slice if the part
exists, or an empty slice if the payload has fewer parts.
Sourcepub fn get(&self, index: usize) -> &[u8] ⓘ
pub fn get(&self, index: usize) -> &[u8] ⓘ
Get a part by index as a byte slice.
Returns an empty slice if the index is out of bounds.