Struct RangeTo

struct RangeTo<Idx> { ... }

A range only bounded exclusively above (..end).

The RangeTo ..end contains all values with x < end. It cannot serve as an Iterator because it doesn't have a starting point.

Examples

The ..end syntax is a RangeTo:

assert_eq!((..5), std::ops::RangeTo { end: 5 });

It does not have an IntoIterator implementation, so you can't use it in a for loop directly. This won't compile:

// error[E0277]: the trait bound `std::ops::RangeTo<{integer}>:
// std::iter::Iterator` is not satisfied
for i in ..5 {
    // ...
}

When used as a slicing index, RangeTo produces a slice of all array elements before the index indicated by end.

let arr = [0, 1, 2, 3, 4];
assert_eq!(arr[ ..  ], [0, 1, 2, 3, 4]);
assert_eq!(arr[ .. 3], [0, 1, 2      ]); // This is a `RangeTo`
assert_eq!(arr[ ..=3], [0, 1, 2, 3   ]);
assert_eq!(arr[1..  ], [   1, 2, 3, 4]);
assert_eq!(arr[1.. 3], [   1, 2      ]);
assert_eq!(arr[1..=3], [   1, 2, 3   ]);

Fields

end: Idx

The upper bound of the range (exclusive).

Implementations

impl<Idx: PartialOrd<Idx>> RangeTo<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!( (..5).contains(&-1_000_000_000));
assert!( (..5).contains(&4));
assert!(!(..5).contains(&5));

assert!( (..1.0).contains(&0.5));
assert!(!(..1.0).contains(&f32::NAN));
assert!(!(..f32::NAN).contains(&0.5));

impl SliceIndex for RangeTo<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 SliceIndex for RangeTo<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<Idx> Freeze for RangeTo<Idx>

impl<Idx> RefUnwindSafe for RangeTo<Idx>

impl<Idx> Send for RangeTo<Idx>

impl<Idx> StructuralPartialEq for RangeTo<Idx>

impl<Idx> Sync for RangeTo<Idx>

impl<Idx> Unpin for RangeTo<Idx>

impl<Idx> UnsafeUnpin for RangeTo<Idx>

impl<Idx> UnwindSafe for RangeTo<Idx>

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

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

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

impl<Idx: $crate::marker::Copy> Copy for RangeTo<Idx>

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

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

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

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

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

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

impl<T> Any for RangeTo<Idx>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for RangeTo<Idx>

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

impl<T> BorrowMut for RangeTo<Idx>

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

impl<T> CloneToUninit for RangeTo<Idx>

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

impl<T> From for RangeTo<Idx>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> IntoBounds for RangeTo<T>

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

impl<T> OneSidedRange for RangeTo<T>

fn bound(self: Self) -> (OneSidedRangeBound, T)

impl<T> RangeBounds for RangeTo<&T>

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

impl<T> RangeBounds for RangeTo<T>

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

impl<T> SliceIndex for RangeTo<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 RangeTo<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 RangeTo<Idx>

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

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

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