pub struct FragmentedByteSlice<'a, B: ByteSlice>(/* private fields */);
Expand description

A wrapper for a sequence of byte slices.

FragmentedByteSlice shares its underlying memory with the slice it was constructed from and, as a result, operations on a FragmentedByteSlice may mutate the backing slice.

Implementations§

source§

impl<'a, B: 'a + Fragment> FragmentedByteSlice<'a, B>

source

pub fn new(bytes: &'a mut [B]) -> Self

Constructs a new FragmentedByteSlice from bytes.

It is important to note that FragmentedByteSlice takes a mutable reference to a backing slice. Operations on the FragmentedByteSlice may mutate bytes as an optimization to avoid extra allocations.

Users are encouraged to treat slices used to construct FragmentedByteSlices as if they are not owned anymore and only serve as (usually temporary) backing for a FragmentedByteSlice.

source

pub fn new_empty() -> Self

Constructs a new empty FragmentedByteSlice.

source

pub fn len(&self) -> usize

Gets the total length, in bytes, of this FragmentedByteSlice.

source

pub fn is_empty(&self) -> bool

Returns true if the FragmentedByteSlice is empty.

source

pub fn slice<R>(self, range: R) -> Self
where R: RangeBounds<usize>,

Slices this FragmentedByteSlice, reducing it to only the bytes within range.

slice will mutate the backing slice by dropping or shrinking fragments as necessary so the overall composition matches the requested range. The returned FragmentedByteSlice uses the same (albeit possibly modified) backing mutable slice reference as self.

§Panics

Panics if the provided range is not within the bounds of this FragmentedByteSlice, or if the range is nonsensical (the end precedes the start).

source

pub fn eq_slice(&self, other: &[u8]) -> bool

Checks whether the contents of this FragmentedByteSlice are equal to the contents of other.

source

pub fn iter(&self) -> impl '_ + Iterator<Item = u8>

Iterates over all the bytes in this FragmentedByteSlice.

source

pub fn iter_fragments(&'a self) -> impl 'a + Iterator<Item = &'a [u8]> + Clone

Iterates over the fragments of this FragmentedByteSlice.

source

pub fn copy_into_slice(&self, dst: &mut [u8])

Copies all the bytes in self into the contiguous slice dst.

§Panics

Panics if dst.len() != self.len().

source

pub fn to_flattened_vec(&self) -> Vec<u8>

Returns a flattened version of this buffer, copying its contents into a Vec.

source

pub fn try_into_contiguous(self) -> Result<B, Self>

Tries to convert this FragmentedByteSlice into a contiguous one.

Returns Ok if self’s backing storage contains 0 or 1 byte slices, and Err otherwise.

If self’s backing storage contains 1 byte slice, that byte slice will be replaced with an empty byte slice, and the original used to construct the return value.

source

pub fn try_get_contiguous(&self) -> Option<&[u8]>

Tries to get a contiguous reference to this FragmentedByteSlice.

Returns Some if self’s backing storage contains 0 or 1 byte slices, and None otherwise.

source

pub fn try_split_contiguous<R>(self, range: R) -> Option<(B, Self, B)>
where R: RangeBounds<usize>,

Tries to split this FragmentedByteSlice into a contiguous prefix, a (possibly fragmented) body, and a contiguous suffix.

Returns None if it isn’t possible to form a contiguous prefix and suffix with the provided range.

§Panics

Panics if the range is out of bounds, or if the range is nonsensical (the end precedes the start).

source§

impl<'a, B: 'a + ByteSliceMut + Fragment> FragmentedByteSlice<'a, B>

source

pub fn iter_mut(&mut self) -> impl '_ + Iterator<Item = &mut u8>

Iterates over mutable references to all the bytes in this FragmentedByteSlice.

source

pub fn copy_from_slice(&mut self, src: &[u8])

Copies all the bytes in src to self.

§Panics

Panics if self.len() != src.len().

source

pub fn copy_from<BB>(&mut self, other: &FragmentedByteSlice<'_, BB>)
where BB: ByteSlice,

Copies all the bytes from another FragmentedByteSlice other into self.

§Panics

Panics if self.len() != other.len().

source

pub fn copy_within<R: RangeBounds<usize>>(&mut self, src: R, dst: usize)

Copies elements from one part of the FragmentedByteSlice to another part of itself.

src is the range within self to copy from. dst is the starting index of the range within self to copy to, which will have the same length as src. The two ranges may overlap. The ends of the two ranges must be less than or equal to self.len().

§Panics

Panics if either the source or destination range is out of bounds, or if src is nonsensical (its end precedes its start).

source

pub fn try_get_contiguous_mut(&mut self) -> Option<&mut [u8]>

Attempts to get a contiguous mutable reference to this FragmentedByteSlice.

Returns Some if this FragmentedByteSlice is a single contiguous part (or is empty). Returns None otherwise.

Trait Implementations§

source§

impl<'a, B: Debug + ByteSlice> Debug for FragmentedByteSlice<'a, B>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a, B: PartialEq + ByteSlice> PartialEq for FragmentedByteSlice<'a, B>

source§

fn eq(&self, other: &FragmentedByteSlice<'a, B>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, B: Eq + ByteSlice> Eq for FragmentedByteSlice<'a, B>

source§

impl<'a, B: ByteSlice> StructuralPartialEq for FragmentedByteSlice<'a, B>

Auto Trait Implementations§

§

impl<'a, B> Freeze for FragmentedByteSlice<'a, B>
where B: ByteSliceSealed + Deref<Target = [u8]>,

§

impl<'a, B> RefUnwindSafe for FragmentedByteSlice<'a, B>
where B: ByteSliceSealed + Deref<Target = [u8]> + RefUnwindSafe,

§

impl<'a, B> Send for FragmentedByteSlice<'a, B>
where B: ByteSliceSealed + Deref<Target = [u8]> + Send,

§

impl<'a, B> Sync for FragmentedByteSlice<'a, B>
where B: ByteSliceSealed + Deref<Target = [u8]> + Sync,

§

impl<'a, B> Unpin for FragmentedByteSlice<'a, B>
where B: ByteSliceSealed + Deref<Target = [u8]>,

§

impl<'a, B> !UnwindSafe for FragmentedByteSlice<'a, B>

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>,

§

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>,

§

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.