SegmentedSlice

Struct SegmentedSlice 

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

Source

pub const fn len(&self) -> usize

Returns the number of elements in the slice.

Source

pub const fn is_empty(&self) -> bool

Returns true if the slice is empty.

Source

pub fn get(&self, index: usize) -> Option<&T>

Returns a reference to the element at the given index, or None if out of bounds.

Source

pub fn first(&self) -> Option<&T>

Returns a reference to the first element, or None if empty.

Source

pub fn last(&self) -> Option<&T>

Returns a reference to the last element, or None if empty.

Source

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.

Source

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.

Source

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.

Source

pub fn iter(&self) -> SliceIter<'a, T, PREALLOC>

Returns an iterator over the slice.

Source

pub fn contains(&self, x: &T) -> bool
where T: PartialEq,

Returns true if the slice contains an element with the given value.

Source

pub fn starts_with(&self, needle: &[T]) -> bool
where T: PartialEq,

Returns true if needle is a prefix of the slice.

Source

pub fn ends_with(&self, needle: &[T]) -> bool
where T: PartialEq,

Returns true if needle is a suffix of the slice.

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.

Source

pub fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
where F: FnMut(&T) -> Ordering,

Binary searches this slice with a comparator function.

Source

pub fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
where F: FnMut(&T) -> B, B: Ord,

Binary searches this slice with a key extraction function.

Source

pub fn slice<R>(self, range: R) -> SegmentedSlice<'a, T, PREALLOC>
where R: SliceIndex<'a, T, PREALLOC, Output = SegmentedSlice<'a, T, PREALLOC>>,

Returns a subslice with elements in the given range.

§Panics

Panics if the range is out of bounds.

Source

pub fn to_vec(&self) -> Vec<T>
where T: Clone,

Copies the elements into a new Vec.

Source

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.

Source

pub fn is_sorted(&self) -> bool
where 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.

Source

pub fn is_sorted_by<F>(&self, compare: F) -> bool
where F: FnMut(&T, &T) -> bool,

Checks if the elements of this slice are sorted using the given comparator function.

Source

pub fn is_sorted_by_key<K, F>(&self, f: F) -> bool
where F: FnMut(&T) -> K, K: PartialOrd,

Checks if the elements of this slice are sorted using the given key extraction function.

Source

pub fn partition_point<P>(&self, pred: P) -> usize
where P: FnMut(&T) -> bool,

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source§

fn clone(&self) -> SegmentedSlice<'a, T, PREALLOC>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T: Debug, const PREALLOC: usize> Debug for SegmentedSlice<'a, T, PREALLOC>

Source§

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

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

impl<'a, T, const PREALLOC: usize> Index<usize> for SegmentedSlice<'a, T, PREALLOC>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, T, const PREALLOC: usize> IntoIterator for &SegmentedSlice<'a, T, PREALLOC>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = SliceIter<'a, T, PREALLOC>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T, const PREALLOC: usize> IntoIterator for SegmentedSlice<'a, T, PREALLOC>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = SliceIter<'a, T, PREALLOC>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T: PartialEq, const PREALLOC: usize> PartialEq<[T]> for SegmentedSlice<'a, T, PREALLOC>

Source§

fn eq(&self, other: &[T]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T: PartialEq, const PREALLOC: usize> PartialEq<Vec<T>> for SegmentedSlice<'a, T, PREALLOC>

Source§

fn eq(&self, other: &Vec<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T: PartialEq, const PREALLOC: usize> PartialEq for SegmentedSlice<'a, T, PREALLOC>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T: Copy, const PREALLOC: usize> Copy for SegmentedSlice<'a, T, PREALLOC>

Source§

impl<'a, T: Eq, const PREALLOC: usize> Eq for SegmentedSlice<'a, T, PREALLOC>

Auto Trait Implementations§

§

impl<'a, T, const PREALLOC: usize> Freeze for SegmentedSlice<'a, T, PREALLOC>

§

impl<'a, T, const PREALLOC: usize> RefUnwindSafe for SegmentedSlice<'a, T, PREALLOC>
where T: RefUnwindSafe,

§

impl<'a, T, const PREALLOC: usize> Send for SegmentedSlice<'a, T, PREALLOC>
where T: Sync,

§

impl<'a, T, const PREALLOC: usize> Sync for SegmentedSlice<'a, T, PREALLOC>
where T: Sync,

§

impl<'a, T, const PREALLOC: usize> Unpin for SegmentedSlice<'a, T, PREALLOC>

§

impl<'a, T, const PREALLOC: usize> UnwindSafe for SegmentedSlice<'a, T, PREALLOC>
where T: RefUnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.