pub struct FragmentedByteSlice<'a, B: SplitByteSlice>(/* 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>
impl<'a, B: 'a + Fragment> FragmentedByteSlice<'a, B>
Sourcepub fn new(bytes: &'a mut [B]) -> Self
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.
Sourcepub fn slice<R>(self, range: R) -> Selfwhere
R: RangeBounds<usize>,
pub fn slice<R>(self, range: R) -> Selfwhere
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).
Sourcepub fn eq_slice(&self, other: &[u8]) -> bool
pub fn eq_slice(&self, other: &[u8]) -> bool
Checks whether the contents of this FragmentedByteSlice are equal to
the contents of other.
Sourcepub fn iter(&self) -> impl '_ + Iterator<Item = u8>
pub fn iter(&self) -> impl '_ + Iterator<Item = u8>
Iterates over all the bytes in this FragmentedByteSlice.
Sourcepub fn iter_fragments(&'a self) -> impl 'a + Iterator<Item = &'a [u8]> + Clone
pub fn iter_fragments(&'a self) -> impl 'a + Iterator<Item = &'a [u8]> + Clone
Iterates over the fragments of this FragmentedByteSlice.
Sourcepub fn copy_into_slice(&self, dst: &mut [u8])
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().
Sourcepub fn to_flattened_vec(&self) -> Vec<u8> ⓘ
pub fn to_flattened_vec(&self) -> Vec<u8> ⓘ
Returns a flattened version of this buffer, copying its contents into a
Vec.
Sourcepub fn try_into_contiguous(self) -> Result<B, Self>
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.
Sourcepub fn try_get_contiguous(&self) -> Option<&[u8]>
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.
Sourcepub fn try_split_contiguous<R>(self, range: R) -> Option<(B, Self, B)>where
R: RangeBounds<usize>,
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 + SplitByteSliceMut + Fragment> FragmentedByteSlice<'a, B>
impl<'a, B: 'a + SplitByteSliceMut + Fragment> FragmentedByteSlice<'a, B>
Sourcepub fn iter_mut(&mut self) -> impl '_ + Iterator<Item = &mut u8>
pub fn iter_mut(&mut self) -> impl '_ + Iterator<Item = &mut u8>
Iterates over mutable references to all the bytes in this
FragmentedByteSlice.
Sourcepub fn copy_from_slice(&mut self, src: &[u8])
pub fn copy_from_slice(&mut self, src: &[u8])
Sourcepub fn copy_from<BB>(&mut self, other: &FragmentedByteSlice<'_, BB>)where
BB: SplitByteSlice,
pub fn copy_from<BB>(&mut self, other: &FragmentedByteSlice<'_, BB>)where
BB: SplitByteSlice,
Copies all the bytes from another FragmentedByteSlice other into
self.
§Panics
Panics if self.len() != other.len().
Sourcepub fn copy_within<R: RangeBounds<usize>>(&mut self, src: R, dst: usize)
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).
Sourcepub fn try_get_contiguous_mut(&mut self) -> Option<&mut [u8]>
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.