SegmentedSliceMut

Struct SegmentedSliceMut 

Source
pub struct SegmentedSliceMut<'a, T, const PREALLOC: usize> { /* private fields */ }
Expand description

A mutable slice view into a SegmentedVec.

This type behaves like &mut [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 mut slice = vec.as_mut_slice();
slice[0] = 100;
assert_eq!(slice[0], 100);

Implementations§

Source§

impl<'a, T, const PREALLOC: usize> SegmentedSliceMut<'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 get_mut(&mut self, index: usize) -> Option<&mut T>

Returns a mutable 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 first_mut(&mut self) -> Option<&mut T>

Returns a mutable 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 last_mut(&mut self) -> Option<&mut T>

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

Source

pub fn swap(&mut self, a: usize, b: usize)

Swaps two elements in the slice.

§Panics

Panics if a or b are out of bounds.

Source

pub fn reverse(&mut self)

Reverses the order of elements in the slice.

Source

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

Returns an iterator over the slice.

Source

pub fn iter_mut(&mut self) -> SliceIterMut<'_, T, PREALLOC>

Returns a mutable 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.

Binary searches this slice for a given element.

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 fill(&mut self, value: T)
where T: Clone,

Fills the slice with the given value.

Source

pub fn fill_with<F>(&mut self, f: F)
where F: FnMut() -> T,

Fills the slice with values produced by a function.

Source

pub fn copy_from_slice(&mut self, src: &[T])
where T: Clone,

Copies elements from src into the slice.

The length of src must be the same as the slice.

§Panics

Panics if the lengths differ.

Source

pub fn sort(&mut self)
where T: Ord,

Sorts the slice.

Source

pub fn sort_by<F>(&mut self, compare: F)
where F: FnMut(&T, &T) -> Ordering,

Sorts the slice with a comparator function.

Source

pub fn sort_by_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord,

Sorts the slice with a key extraction function.

Source

pub fn sort_unstable(&mut self)
where T: Ord,

Sorts the slice using an unstable algorithm.

Source

pub fn sort_unstable_by<F>(&mut self, compare: F)
where F: FnMut(&T, &T) -> Ordering,

Sorts the slice with a comparator function using an unstable algorithm.

Source

pub fn sort_unstable_by_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord,

Sorts the slice with a key extraction function using an unstable algorithm.

Source

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

Copies the elements into a new Vec.

Source

pub fn as_slice(&self) -> SegmentedSlice<'_, T, PREALLOC>

Returns an immutable view of this slice.

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 unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T

Returns a mutable reference to an element without bounds checking.

§Safety

Calling this method with an out-of-bounds index is undefined behavior.

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.

Source

pub fn is_sorted(&self) -> bool
where T: PartialOrd,

Checks if the elements of this slice are sorted.

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.

Source

pub fn rotate_left(&mut self, mid: usize)

Rotates the slice in-place such that the first mid elements move to the end.

After calling rotate_left, the element previously at index mid is now at index 0.

§Panics

Panics if mid > len.

Source

pub fn rotate_right(&mut self, k: usize)

Rotates the slice in-place such that the last k elements move to the front.

After calling rotate_right, the element previously at index len - k is now at index 0.

§Panics

Panics if k > len.

Source

pub fn split_at_mut( self, mid: usize, ) -> (SegmentedSliceMut<'a, T, PREALLOC>, SegmentedSliceMut<'a, T, PREALLOC>)

Divides one mutable 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.

§Note

Due to borrowing rules, this method consumes self and returns two new slices.

Source

pub fn chunks(&self, chunk_size: usize) -> Chunks<'_, T, PREALLOC>

Returns an iterator over chunk_size elements of the slice at a time.

§Panics

Panics if chunk_size is 0.

Source

pub fn windows(&self, size: usize) -> Windows<'_, T, PREALLOC>

Returns an iterator over all contiguous windows of length size.

§Panics

Panics if size is 0.

Trait Implementations§

Source§

impl<'a, T: Debug, const PREALLOC: usize> Debug for SegmentedSliceMut<'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 SegmentedSliceMut<'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> IndexMut<usize> for SegmentedSliceMut<'a, T, PREALLOC>

Source§

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

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, T, const PREALLOC: usize> !UnwindSafe for SegmentedSliceMut<'a, T, PREALLOC>

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

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.