Struct RangeToInclusive

struct RangeToInclusive<Idx> { ... }

A range only bounded inclusively above (..=last).

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

Examples

The ..=last syntax is a RangeToInclusive:

#![feature(new_range_api)]
#![feature(new_range)]
assert_eq!((..=5), std::range::RangeToInclusive{ last: 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::range::RangeToInclusive<{integer}>:
// std::iter::Iterator` is not satisfied
for i in ..=5 {
    // ...
}

When used as a slicing index, RangeToInclusive produces a slice of all array elements up to and including the index indicated by last.

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   ]); // This is a `RangeToInclusive`
assert_eq!(arr[1..  ], [   1, 2, 3, 4]);
assert_eq!(arr[1.. 3], [   1, 2      ]);
assert_eq!(arr[1..=3], [   1, 2, 3   ]);

Fields

last: Idx

The upper bound of the range (inclusive)

Implementations

impl<Idx: PartialOrd<Idx>> RangeToInclusive<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(&5));
assert!(!(..=5).contains(&6));

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

impl<Idx> Freeze for RangeToInclusive<Idx>

impl<Idx> RefUnwindSafe for RangeToInclusive<Idx>

impl<Idx> Send for RangeToInclusive<Idx>

impl<Idx> StructuralPartialEq for RangeToInclusive<Idx>

impl<Idx> Sync for RangeToInclusive<Idx>

impl<Idx> Unpin for RangeToInclusive<Idx>

impl<Idx> UnwindSafe for RangeToInclusive<Idx>

impl<Idx: $crate::clone::Clone> Clone for RangeToInclusive<Idx>

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

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

impl<Idx: $crate::cmp::PartialEq> PartialEq for RangeToInclusive<Idx>

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

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

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

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

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

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

impl<T> Any for RangeToInclusive<Idx>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for RangeToInclusive<Idx>

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

impl<T> BorrowMut for RangeToInclusive<Idx>

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

impl<T> CloneToUninit for RangeToInclusive<Idx>

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

impl<T> From for RangeToInclusive<Idx>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> From for RangeToInclusive<T>

fn from(value: legacy::RangeToInclusive<T>) -> Self

impl<T> IntoBounds for RangeToInclusive<T>

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

impl<T> RangeBounds for RangeToInclusive<T>

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

impl<T> SliceIndex for range::RangeToInclusive<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 RangeToInclusive<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 RangeToInclusive<Idx>

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

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

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