Struct Range

struct Range<Idx> { ... }

A (half-open) range bounded inclusively below and exclusively above (start..end).

The range start..end contains all values with start <= x < end. It is empty if start >= end.

Examples

The start..end syntax is a Range:

assert_eq!((3..5), std::ops::Range { start: 3, end: 5 });
assert_eq!(3 + 4 + 5, (3..6).sum());
let arr = [0, 1, 2, 3, 4];
assert_eq!(arr[ ..  ], [0, 1, 2, 3, 4]);
assert_eq!(arr[ .. 3], [0, 1, 2      ]);
assert_eq!(arr[ ..=3], [0, 1, 2, 3   ]);
assert_eq!(arr[1..  ], [   1, 2, 3, 4]);
assert_eq!(arr[1.. 3], [   1, 2      ]); // This is a `Range`
assert_eq!(arr[1..=3], [   1, 2, 3   ]);

Fields

start: Idx

The lower bound of the range (inclusive).

end: Idx

The upper bound of the range (exclusive).

Implementations

impl<Idx: PartialOrd<Idx>> Range<Idx>

const fn contains<U>(self: &Self, item: &U) -> bool
where
    Idx: ~const PartialOrd<U>,
    U: ?Sized + ~const PartialOrd<Idx>

Returns true if item is contained in the range.

Examples

assert!(!(3..5).contains(&2));
assert!( (3..5).contains(&3));
assert!( (3..5).contains(&4));
assert!(!(3..5).contains(&5));

assert!(!(3..3).contains(&3));
assert!(!(3..2).contains(&3));

assert!( (0.0..1.0).contains(&0.5));
assert!(!(0.0..1.0).contains(&f32::NAN));
assert!(!(0.0..f32::NAN).contains(&0.5));
assert!(!(f32::NAN..1.0).contains(&0.5));
const fn is_empty(self: &Self) -> bool
where
    Idx: ~const PartialOrd<Idx>

Returns true if the range contains no items.

Examples

assert!(!(3..5).is_empty());
assert!( (3..3).is_empty());
assert!( (3..2).is_empty());

The range is empty if either side is incomparable:

assert!(!(3.0..5.0).is_empty());
assert!( (3.0..f32::NAN).is_empty());
assert!( (f32::NAN..5.0).is_empty());

impl ExactSizeIterator for Range<i16>

impl ExactSizeIterator for Range<i32>

impl ExactSizeIterator for Range<i8>

impl ExactSizeIterator for Range<isize>

impl ExactSizeIterator for Range<u16>

impl ExactSizeIterator for Range<u32>

impl ExactSizeIterator for Range<u8>

impl ExactSizeIterator for Range<usize>

impl GetDisjointMutIndex for Range<usize>

fn is_in_bounds(self: &Self, len: usize) -> bool
fn is_overlapping(self: &Self, other: &Self) -> bool

impl SliceIndex for Range<usize>

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

impl SliceIndex for Range<usize>

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

impl<A: Step> DoubleEndedIterator for Range<A>

fn next_back(self: &mut Self) -> Option<A>
fn nth_back(self: &mut Self, n: usize) -> Option<A>
fn advance_back_by(self: &mut Self, n: usize) -> Result<(), NonZero<usize>>

impl<A: Step> FusedIterator for Range<A>

impl<A: Step> Iterator for Range<A>

fn next(self: &mut Self) -> Option<A>
fn size_hint(self: &Self) -> (usize, Option<usize>)
fn count(self: Self) -> usize
fn nth(self: &mut Self, n: usize) -> Option<A>
fn last(self: Self) -> Option<A>
fn min(self: Self) -> Option<A>
where
    A: Ord
fn max(self: Self) -> Option<A>
where
    A: Ord
fn is_sorted(self: Self) -> bool
fn advance_by(self: &mut Self, n: usize) -> Result<(), NonZero<usize>>

impl<A: TrustedStep> TrustedLen for Range<A>

impl<I> IntoIterator for Range<Idx>

fn into_iter(self: Self) -> I

impl<Idx> Freeze for Range<Idx>

impl<Idx> RefUnwindSafe for Range<Idx>

impl<Idx> Send for Range<Idx>

impl<Idx> StructuralPartialEq for Range<Idx>

impl<Idx> Sync for Range<Idx>

impl<Idx> Unpin for Range<Idx>

impl<Idx> UnsafeUnpin for Range<Idx>

impl<Idx> UnwindSafe for Range<Idx>

impl<Idx: $crate::cmp::Eq> Eq for Range<Idx>

impl<Idx: $crate::hash::Hash> Hash for Range<Idx>

fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)

impl<Idx: fmt::Debug> Debug for Range<Idx>

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

impl<Idx: ~const $crate::clone::Clone> Clone for Range<Idx>

fn clone(self: &Self) -> Range<Idx>

impl<Idx: ~const $crate::cmp::PartialEq> PartialEq for Range<Idx>

fn eq(self: &Self, other: &Range<Idx>) -> bool

impl<Idx: ~const $crate::default::Default> Default for Range<Idx>

fn default() -> Range<Idx>

impl<T> Any for Range<Idx>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Range<Idx>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Range<Idx>

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

impl<T> CloneToUninit for Range<Idx>

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

impl<T> From for Range<Idx>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> From for Range<T>

fn from(value: Range<T>) -> Self

impl<T> IntoBounds for Range<T>

fn into_bounds(self: Self) -> (Bound<T>, Bound<T>)

impl<T> RangeBounds for Range<&T>

fn start_bound(self: &Self) -> Bound<&T>
fn end_bound(self: &Self) -> Bound<&T>

impl<T> RangeBounds for Range<T>

fn start_bound(self: &Self) -> Bound<&T>
fn end_bound(self: &Self) -> Bound<&T>

impl<T> SliceIndex for Range<usize>

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

impl<T, U> Into for Range<Idx>

fn into(self: 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 for Range<Idx>

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

impl<T, U> TryInto for Range<Idx>

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

impl<T: CloneFromCell> CloneFromCell for Range<T>