Skip to main content

PayloadParts

Struct PayloadParts 

Source
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

Source

pub fn split(payload: Bytes, delimiter: &[u8]) -> Self

Split a payload by the given delimiter.

§Arguments
  • payload - The payload to split
  • delimiter - 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
Source

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 split
  • finder - Pre-built delimiter finder
  • delim_len - Length of the delimiter in bytes
Source

pub fn new_lazy(payload: Bytes) -> Self

Create a lazy payload splitter that scans delimiters on demand.

No scanning happens until ensure() is called.

Source

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.

Source

pub fn len(&self) -> usize

Get the number of parts.

Source

pub fn is_empty(&self) -> bool

Check if there are no parts.

Source

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.

Source

pub fn get_bytes(&self, index: usize) -> Bytes

Get a part by index as a Bytes (zero-copy slice).

Returns an empty Bytes if the index is out of bounds.

Source

pub fn payload(&self) -> &Bytes

Get the original payload.

Source

pub fn iter(&self) -> impl Iterator<Item = &[u8]>

Iterate over all parts as byte slices.

Trait Implementations§

Source§

impl Debug for PayloadParts

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.