pub struct Region<'a, T>(/* private fields */);
Expand description
A region of two separate slices that represent continuous data.
Ring
implements a “ring-buffer”, meaning the left and right regions can overlap the ends of
the underlying buffer, causing them to be split into two contiguous slices (chunks). Region
represents these two chunks, allowing their data to be accessed mostly like one continuous slice
without allocations or copies.
Implementations§
Source§impl<'a, T> Region<'a, T>
impl<'a, T> Region<'a, T>
Sourcepub fn new(slice_0: &'a [T], slice_1: &'a [T]) -> Self
pub fn new(slice_0: &'a [T], slice_1: &'a [T]) -> Self
Creates a region with two slices.
The slices should represent continuous data, where slice_0
goes before slice_1
.
Sourcepub fn iter(&self) -> impl Iterator<Item = &'a T> + 'a
pub fn iter(&self) -> impl Iterator<Item = &'a T> + 'a
Returns an iterator over the region.
The iterator yields all items from start to end.
Sourcepub fn contiguous(&self) -> &'a [T]
pub fn contiguous(&self) -> &'a [T]
Returns the first contiguous slice in the region.
The slice will not necessarily contain all data in the region. If the region is not empty, the slice is guaranteed to contain some data.
Sourcepub fn slice<R>(&self, range: R) -> Selfwhere
R: RangeBounds<usize>,
pub fn slice<R>(&self, range: R) -> Selfwhere
R: RangeBounds<usize>,
Slices the region, returning a new region containing a part of the original.
§Panics
Panics if the start
or end
of the range is >= region.len()
.
Source§impl<'a, T> Region<'a, T>where
T: Copy,
impl<'a, T> Region<'a, T>where
T: Copy,
Sourcepub fn copy_to_slice(&self, dest: &mut [T])
pub fn copy_to_slice(&self, dest: &mut [T])
Copies all elements in the region into dest
, using a memcpy.
The length of dest
must be the same as self
.
If T
does not implement Copy
, use clone_to_slice
.
§Panics
This function will panic if dest
has a different length to self
.