pub struct Slice<T> { /* private fields */ }
Expand description
Implementations§
Source§impl<T> Slice<T>
impl<T> Slice<T>
Sourcepub fn get_index(&self, index: usize) -> Option<&T>
pub fn get_index(&self, index: usize) -> Option<&T>
Get a value by index.
Valid indices are 0 <= index < self.len()
.
Sourcepub fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Self>
pub fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Self>
Returns a slice of values in the given range of indices.
Valid indices are 0 <= index < self.len()
.
Sourcepub fn split_at(&self, index: usize) -> (&Self, &Self)
pub fn split_at(&self, index: usize) -> (&Self, &Self)
Divides one slice into two at an index.
Panics if index > len
.
Sourcepub fn split_first(&self) -> Option<(&T, &Self)>
pub fn split_first(&self) -> Option<(&T, &Self)>
Returns the first value and the rest of the slice,
or None
if it is empty.
Sourcepub fn split_last(&self) -> Option<(&T, &Self)>
pub fn split_last(&self) -> Option<(&T, &Self)>
Returns the last value and the rest of the slice,
or None
if it is empty.
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,
Search over a sorted set for a value.
Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See slice::binary_search
for more details.
Computes in O(log(n)) time, which is notably less scalable than looking the value up in
the set this is a slice from using IndexSet::get_index_of
, but this can also position
missing values.
Sourcepub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
Search over a sorted set with a comparator function.
Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See slice::binary_search_by
for more details.
Computes in O(log(n)) time.
Sourcepub fn binary_search_by_key<'a, B, F>(
&'a self,
b: &B,
f: F,
) -> Result<usize, usize>
pub fn binary_search_by_key<'a, B, F>( &'a self, b: &B, f: F, ) -> Result<usize, usize>
Search over a sorted set with an extraction function.
Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See slice::binary_search_by_key
for more details.
Computes in O(log(n)) time.
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 of a sorted set according to the given predicate (the index of the first element of the second partition).
See slice::partition_point
for more details.
Computes in O(log(n)) time.
Trait Implementations§
Source§impl<'a, T> IntoIterator for &'a Slice<T>
impl<'a, T> IntoIterator for &'a Slice<T>
Source§impl<T> IntoIterator for Box<Slice<T>>
impl<T> IntoIterator for Box<Slice<T>>
Source§impl<T: PartialOrd> PartialOrd for Slice<T>
impl<T: PartialOrd> PartialOrd for Slice<T>
impl<T: Eq> Eq for Slice<T>
Auto Trait Implementations§
impl<T> Freeze for Slice<T>where
T: Freeze,
impl<T> RefUnwindSafe for Slice<T>where
T: RefUnwindSafe,
impl<T> Send for Slice<T>where
T: Send,
impl<T> !Sized for Slice<T>
impl<T> Sync for Slice<T>where
T: Sync,
impl<T> Unpin for Slice<T>where
T: Unpin,
impl<T> UnwindSafe for Slice<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.