pub struct SegmentedSlice<'a, T, const PREALLOC: usize> { /* private fields */ }Expand description
An immutable slice view into a SegmentedVec.
This type behaves like &[T] but works with non-contiguous memory.
§Example
use segmented_vec::SegmentedVec;
let mut vec: SegmentedVec<i32, 4> = SegmentedVec::new();
vec.extend(0..10);
let slice = vec.as_slice();
assert_eq!(slice.len(), 10);
assert_eq!(slice[0], 0);
assert_eq!(slice.first(), Some(&0));Implementations§
Source§impl<'a, T, const PREALLOC: usize> SegmentedSlice<'a, T, PREALLOC>
impl<'a, T, const PREALLOC: usize> SegmentedSlice<'a, T, PREALLOC>
Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Returns a reference to the element at the given index, or None if out of bounds.
Sourcepub fn split_first(&self) -> Option<(&T, SegmentedSlice<'a, T, PREALLOC>)>
pub fn split_first(&self) -> Option<(&T, SegmentedSlice<'a, T, PREALLOC>)>
Returns references to the first and rest of the elements, or None if empty.
Sourcepub fn split_last(&self) -> Option<(&T, SegmentedSlice<'a, T, PREALLOC>)>
pub fn split_last(&self) -> Option<(&T, SegmentedSlice<'a, T, PREALLOC>)>
Returns references to the last and rest of the elements, or None if empty.
Sourcepub fn split_at(
&self,
mid: usize,
) -> (SegmentedSlice<'a, T, PREALLOC>, SegmentedSlice<'a, T, PREALLOC>)
pub fn split_at( &self, mid: usize, ) -> (SegmentedSlice<'a, T, PREALLOC>, SegmentedSlice<'a, T, PREALLOC>)
Divides the slice into two at an index.
The first will contain all indices from [0, mid) and the second will contain
all indices from [mid, len).
§Panics
Panics if mid > len.
Sourcepub fn contains(&self, x: &T) -> boolwhere
T: PartialEq,
pub fn contains(&self, x: &T) -> boolwhere
T: PartialEq,
Returns true if the slice contains an element with the given value.
Sourcepub fn starts_with(&self, needle: &[T]) -> boolwhere
T: PartialEq,
pub fn starts_with(&self, needle: &[T]) -> boolwhere
T: PartialEq,
Returns true if needle is a prefix of the slice.
Sourcepub fn ends_with(&self, needle: &[T]) -> boolwhere
T: PartialEq,
pub fn ends_with(&self, needle: &[T]) -> boolwhere
T: PartialEq,
Returns true if needle is a suffix of the slice.
Sourcepub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,
pub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,
Binary searches this slice for a given element.
If the value is found, returns Ok(index). If not found, returns
Err(index) where index is the position where the element could be inserted.
Sourcepub fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
pub fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
Binary searches this slice with a comparator function.
Sourcepub fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
pub fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
Binary searches this slice with a key extraction function.
Sourcepub fn slice<R>(self, range: R) -> SegmentedSlice<'a, T, PREALLOC>where
R: SliceIndex<'a, T, PREALLOC, Output = SegmentedSlice<'a, T, PREALLOC>>,
pub fn slice<R>(self, range: R) -> SegmentedSlice<'a, T, PREALLOC>where
R: SliceIndex<'a, T, PREALLOC, Output = SegmentedSlice<'a, T, PREALLOC>>,
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> &T
pub unsafe fn get_unchecked(&self, index: usize) -> &T
Returns a reference to an element without bounds checking.
§Safety
Calling this method with an out-of-bounds index is undefined behavior.
Sourcepub fn is_sorted(&self) -> boolwhere
T: PartialOrd,
pub fn is_sorted(&self) -> boolwhere
T: PartialOrd,
Checks if the elements of this slice are sorted.
That is, for each element a and its following element b, a <= b must hold.
Sourcepub fn is_sorted_by<F>(&self, compare: F) -> bool
pub fn is_sorted_by<F>(&self, compare: F) -> bool
Checks if the elements of this slice are sorted using the given comparator function.
Sourcepub fn is_sorted_by_key<K, F>(&self, f: F) -> bool
pub fn is_sorted_by_key<K, F>(&self, f: F) -> bool
Checks if the elements of this slice are sorted using the given key extraction function.
Sourcepub fn partition_point<P>(&self, pred: P) -> usize
pub fn partition_point<P>(&self, pred: P) -> usize
Returns the index of the partition point according to the given predicate.
The slice is assumed to be partitioned according to the given predicate.
This returns the first index where the predicate returns false.
Sourcepub fn windows(&self, size: usize) -> Windows<'a, T, PREALLOC> ⓘ
pub fn windows(&self, size: usize) -> Windows<'a, T, PREALLOC> ⓘ
Returns an iterator over all contiguous windows of length size.
The windows overlap. If the slice is shorter than size, the iterator returns no values.
§Panics
Panics if size is 0.
Sourcepub fn chunks(&self, chunk_size: usize) -> Chunks<'a, T, PREALLOC> ⓘ
pub fn chunks(&self, chunk_size: usize) -> Chunks<'a, T, PREALLOC> ⓘ
Returns an iterator over chunk_size elements of the slice at a time.
The chunks are slices and do not overlap. If chunk_size does not divide the length
of the slice, then the last chunk will not have length chunk_size.
§Panics
Panics if chunk_size is 0.
Sourcepub fn rchunks(&self, chunk_size: usize) -> RChunks<'a, T, PREALLOC> ⓘ
pub fn rchunks(&self, chunk_size: usize) -> RChunks<'a, T, PREALLOC> ⓘ
Returns an iterator over chunk_size elements of the slice at a time, starting at the end.
The chunks are slices and do not overlap. If chunk_size does not divide the length
of the slice, then the last chunk will not have length chunk_size.
§Panics
Panics if chunk_size is 0.
Sourcepub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'a, T, PREALLOC> ⓘ
pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'a, T, PREALLOC> ⓘ
Returns an iterator over chunk_size elements of the slice at a time.
If chunk_size does not divide the length, the last up to chunk_size-1
elements will be omitted and can be retrieved from the remainder function
of the iterator.
§Panics
Panics if chunk_size is 0.
Trait Implementations§
Source§impl<'a, T: Clone, const PREALLOC: usize> Clone for SegmentedSlice<'a, T, PREALLOC>
impl<'a, T: Clone, const PREALLOC: usize> Clone for SegmentedSlice<'a, T, PREALLOC>
Source§fn clone(&self) -> SegmentedSlice<'a, T, PREALLOC>
fn clone(&self) -> SegmentedSlice<'a, T, PREALLOC>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more