Struct Slice

#[repr(transparent)]
pub struct Slice<T> { /* private fields */ }

A dynamically-sized slice of values in an IndexSet.

This supports indexed operations much like a [T] slice, but not any hashed operations on the values.

Unlike IndexSet, Slice does consider the order for PartialEq and Eq, and it also implements PartialOrd, Ord, and Hash.

Implementations

impl<T> Slice<T>

const fn new<'a>() -> &'a Self

Returns an empty slice.

const fn len(&self) -> usize

Return the number of elements in the set slice.

const fn is_empty(&self) -> bool

Returns true if the set slice contains no elements.

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

Get a value by index.

Valid indices are 0 <= index < self.len().

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().

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

Get the first value.

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

Get the last value.

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

Divides one slice into two at an index.

Panics if index > len. For a non-panicking alternative see [split_at_checked][Self::split_at_checked].

const fn split_at_checked(&self, index: usize) -> Option<(&Self, &Self)>

Divides one slice into two at an index.

Returns None if index > len.

const fn split_first(&self) -> Option<(&T, &Self)>

Returns the first value and the rest of the slice, or None if it is empty.

const fn split_last(&self) -> Option<(&T, &Self)>

Returns the last value and the rest of the slice, or None if it is empty.

fn iter(&self) -> Iter<'_, T>

Return an iterator over the values of the set slice.

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.

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

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.

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

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.

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

Checks if the values of this slice are sorted.

fn is_sorted_by<'a, F>(&'a self, cmp: F) -> bool
where
    F: FnMut(&'a T, &'a T) -> bool,

Checks if this slice is sorted using the given comparator function.

fn is_sorted_by_key<'a, F, K>(&'a self, sort_key: F) -> bool
where
    F: FnMut(&'a T) -> K,
    K: PartialOrd,

Checks if this slice is sorted using the given sort-key function.

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

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

impl<T> Index<(Bound<usize>, Bound<usize>)> for Slice<T>

type Output = Slice<T>;
fn index(&self, range: (Bound<usize>, Bound<usize>)) -> &Self::Output

impl<T> Index<Range<usize>> for Slice<T>

type Output = Slice<T>;
fn index(&self, range: Range<usize>) -> &Self::Output

impl<T> Index<RangeFrom<usize>> for Slice<T>

type Output = Slice<T>;
fn index(&self, range: RangeFrom<usize>) -> &Self::Output

impl<T> Index<RangeFull> for Slice<T>

type Output = Slice<T>;
fn index(&self, range: RangeFull) -> &Self::Output

impl<T> Index<RangeInclusive<usize>> for Slice<T>

type Output = Slice<T>;
fn index(&self, range: RangeInclusive<usize>) -> &Self::Output

impl<T> Index<RangeTo<usize>> for Slice<T>

type Output = Slice<T>;
fn index(&self, range: RangeTo<usize>) -> &Self::Output

impl<T> Index<RangeToInclusive<usize>> for Slice<T>

type Output = Slice<T>;
fn index(&self, range: RangeToInclusive<usize>) -> &Self::Output

impl<T> Index<usize> for Slice<T>

type Output = T;
fn index(&self, index: usize) -> &Self::Output

impl<T, U> PartialEq<Slice<U>> for Slice<T> where T: PartialEq<U>,

fn eq(&self, other: &Slice<U>) -> bool

impl<T, U> PartialEq<[U]> for Slice<T> where T: PartialEq<U>,

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

impl<T, U, const N: usize> PartialEq<[U; N]> for Slice<T> where T: PartialEq<U>,

fn eq(&self, other: &[U; N]) -> bool

impl<T: Debug> Debug for Slice<T>

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

impl<T: Eq> Eq for Slice<T>

impl<T: Hash> Hash for Slice<T>

fn hash<H: Hasher>(&self, state: &mut H)

impl<T: Ord> Ord for Slice<T>

fn cmp(&self, other: &Self) -> Ordering

impl<T: PartialOrd> PartialOrd for Slice<T>

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

Auto Trait Implementations

impl<T> !Sized for Slice<T>

impl<T> Freeze for Slice<T> where [Bucket<T, ()>]: Freeze,

impl<T> RefUnwindSafe for Slice<T> where [Bucket<T, ()>]: RefUnwindSafe,

impl<T> Send for Slice<T> where [Bucket<T, ()>]: Send,

impl<T> Sync for Slice<T> where [Bucket<T, ()>]: Sync,

impl<T> Unpin for Slice<T> where [Bucket<T, ()>]: Unpin,

impl<T> UnsafeUnpin for Slice<T> where [Bucket<T, ()>]: UnsafeUnpin,

impl<T> UnwindSafe for Slice<T> where [Bucket<T, ()>]: UnwindSafe,

Blanket Implementations

impl<Q, K> Comparable<K> for Slice<T> where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

fn compare(&self, key: &K) -> Ordering

impl<Q, K> Equivalent<K> for Slice<T> where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

fn equivalent(&self, key: &K) -> bool

impl<Q, K> Equivalent<K> for Slice<T> where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

fn equivalent(&self, key: &K) -> bool

impl<T> Any for Slice<T> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Slice<T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Slice<T> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T