pub struct SegmentedSliceMut<'a, T> { /* 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> = 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> SegmentedSliceMut<'a, T>
impl<'a, T> SegmentedSliceMut<'a, T>
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 get_mut(&mut self, index: usize) -> Option<&mut T>
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.
Sourcepub fn first_mut(&mut self) -> Option<&mut T>
pub fn first_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the first element, or None if empty.
Sourcepub fn last_mut(&mut self) -> Option<&mut T>
pub fn last_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the last element, or None if empty.
Sourcepub fn iter_mut(&mut self) -> SliceIterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> SliceIterMut<'_, T> ⓘ
Returns a mutable iterator over the slice.
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 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.
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 fill_with<F>(&mut self, f: F)where
F: FnMut() -> T,
pub fn fill_with<F>(&mut self, f: F)where
F: FnMut() -> T,
Fills the slice with values produced by a function.
Sourcepub fn copy_from_slice(&mut self, src: &[T])where
T: Clone,
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.
Sourcepub fn sort_by_key<K, F>(&mut self, f: F)
pub fn sort_by_key<K, F>(&mut self, f: F)
Sorts the slice with a key extraction function.
Sourcepub fn sort_unstable(&mut self)where
T: Ord,
pub fn sort_unstable(&mut self)where
T: Ord,
Sorts the slice using an unstable algorithm.
Sourcepub fn sort_unstable_by<F>(&mut self, compare: F)
pub fn sort_unstable_by<F>(&mut self, compare: F)
Sorts the slice with a comparator function using an unstable algorithm.
Sourcepub fn sort_unstable_by_key<K, F>(&mut self, f: F)
pub fn sort_unstable_by_key<K, F>(&mut self, f: F)
Sorts the slice with a key extraction function using an unstable algorithm.
Sourcepub fn as_slice(&self) -> SegmentedSlice<'_, T>
pub fn as_slice(&self) -> SegmentedSlice<'_, T>
Returns an immutable view of this slice.
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 unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T
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.
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 is_sorted(&self) -> boolwhere
T: PartialOrd,
pub fn is_sorted(&self) -> boolwhere
T: PartialOrd,
Checks if the elements of this slice are sorted.
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.
Sourcepub fn rotate_left(&mut self, mid: usize)
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.
Sourcepub fn rotate_right(&mut self, k: usize)
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.