Struct IndexRange

pub(crate) struct IndexRange { pub(in ::ops::index_range) start: usize, pub(in ::ops::index_range) end: usize }

Like a Range<usize>, but with a safety invariant that start <= end.

This means that end - start cannot overflow, allowing some μoptimizations.

(Normal Range code needs to handle degenerate ranges like 10..0, which takes extra checks compared to only handling the canonical form.)

Fields

start: usize
end: usize

Implementations

impl IndexRange

const unsafe fn new_unchecked(start: usize, end: usize) -> Self

Safety

  • start <= end
const fn zero_to(end: usize) -> Self
const fn start(&self) -> usize
const fn end(&self) -> usize
const fn len(&self) -> usize
const unsafe fn next_unchecked(&mut self) -> usize

Safety

  • Can only be called when start < end, aka when len > 0.
const unsafe fn next_back_unchecked(&mut self) -> usize

Safety

  • Can only be called when start < end, aka when len > 0.
fn take_prefix(&mut self, n: usize) -> Self

Removes the first n items from this range, returning them as an IndexRange. If there are fewer than n, then the whole range is returned and self is left empty.

This is designed to help implement Iterator::advance_by.

fn take_suffix(&mut self, n: usize) -> Self

Removes the last n items from this range, returning them as an IndexRange. If there are fewer than n, then the whole range is returned and self is left empty.

This is designed to help implement Iterator::advance_back_by.

const fn assume_range(&self)

Trait Implementations

impl Clone for IndexRange

fn clone(&self) -> IndexRange

impl Debug for IndexRange

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

impl DoubleEndedIterator for IndexRange

fn next_back(&mut self) -> Option<usize>
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
fn rfold<B, F: FnMut(B, usize) -> B>(self, init: B, f: F) -> B
fn try_rfold<B, F, R>(&mut self, accum: B, f: F) -> R
where
    Self: Sized,
    F: FnMut(B, Self::Item) -> R,
    R: Try<Output = B>,

impl Eq for IndexRange

fn assert_fields_are_eq(&self)

impl ExactSizeIterator for IndexRange

fn len(&self) -> usize

impl FusedIterator for IndexRange

impl Iterator for IndexRange

type Item = usize;
fn next(&mut self) -> Option<usize>
fn size_hint(&self) -> (usize, Option<usize>)
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
fn fold<B, F: FnMut(B, usize) -> B>(self, init: B, f: F) -> B
fn try_fold<B, F, R>(&mut self, accum: B, f: F) -> R
where
    Self: Sized,
    F: FnMut(B, Self::Item) -> R,
    R: Try<Output = B>,

impl PartialEq for IndexRange

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

impl SliceIndex<ByteStr> for IndexRange

type Output = ByteStr;
fn get(self, slice: &ByteStr) -> Option<&Self::Output>
fn get_mut(self, slice: &mut ByteStr) -> Option<&mut Self::Output>
unsafe fn get_unchecked(self, slice: *const ByteStr) -> *const Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut ByteStr) -> *mut Self::Output
fn index(self, slice: &ByteStr) -> &Self::Output
fn index_mut(self, slice: &mut ByteStr) -> &mut Self::Output

impl StructuralPartialEq for IndexRange

impl TrustedLen for IndexRange

impl<T> SliceIndex<[T]> for IndexRange

type Output = [T];
fn get(self, slice: &[T]) -> Option<&[T]>
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>
unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]
fn index(self, slice: &[T]) -> &[T]
fn index_mut(self, slice: &mut [T]) -> &mut [T]

Auto Trait Implementations

impl Freeze for IndexRange

impl RefUnwindSafe for IndexRange

impl Send for IndexRange

impl Sync for IndexRange

impl Unpin for IndexRange

impl UnsafeUnpin for IndexRange

impl UnwindSafe for IndexRange

Blanket Implementations

impl<I> IntoIterator for IndexRange where I: Iterator,

type Item = <I as Iterator>::Item;
type IntoIter = I;
fn into_iter(self) -> I

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> CloneToUninit for IndexRange where T: Clone,

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

impl<T> From<T> for IndexRange

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for IndexRange where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for IndexRange

impl<T, U> Into<U> for IndexRange where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for IndexRange where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for IndexRange where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>