Struct RangeToInclusive

pub struct RangeToInclusive<Idx> { pub end: Idx }

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

The RangeToInclusive ..=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 RangeToInclusive:

assert_eq!((..=5), std::ops::RangeToInclusive{ 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::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 end.

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

end: Idx

The upper bound of the range (inclusive)

Implementations

impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx>

const fn contains<U>(&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));

Trait Implementations

impl SliceIndex<ByteStr> for RangeToInclusive<usize>

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 SliceIndex<str> for RangeToInclusive<usize>

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

impl<Idx: Clone> Clone for RangeToInclusive<Idx>

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

impl<Idx: Copy> Copy for RangeToInclusive<Idx>

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

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

impl<Idx: Eq> Eq for RangeToInclusive<Idx>

fn assert_fields_are_eq(&self)

impl<Idx: Hash> Hash for RangeToInclusive<Idx>

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

impl<Idx: PartialEq> PartialEq for RangeToInclusive<Idx>

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

impl<Idx: PartialEq> StructuralPartialEq for RangeToInclusive<Idx>

impl<T> From<RangeToInclusive<T>> for RangeToInclusive<T>

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

impl<T> IntoBounds<T> for RangeToInclusive<T>

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

impl<T> OneSidedRange<T> for RangeToInclusive<T> where Self: RangeBounds<T>,

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

impl<T> RangeBounds<T> for RangeToInclusive<&T>

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

impl<T> RangeBounds<T> for RangeToInclusive<T>

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

impl<T> SliceIndex<[T]> for RangeToInclusive<usize>

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<Idx> Freeze for RangeToInclusive<Idx> where Idx: Freeze,

impl<Idx> RefUnwindSafe for RangeToInclusive<Idx> where Idx: RefUnwindSafe,

impl<Idx> Send for RangeToInclusive<Idx> where Idx: Send,

impl<Idx> Sync for RangeToInclusive<Idx> where Idx: Sync,

impl<Idx> Unpin for RangeToInclusive<Idx> where Idx: Unpin,

impl<Idx> UnsafeUnpin for RangeToInclusive<Idx> where Idx: UnsafeUnpin,

impl<Idx> UnwindSafe for RangeToInclusive<Idx> where Idx: UnwindSafe,

Blanket Implementations

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for RangeToInclusive<Idx> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for RangeToInclusive<Idx> where T: ?Sized,

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

impl<T> CloneToUninit for RangeToInclusive<Idx> where T: Clone,

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

impl<T> From<T> for RangeToInclusive<Idx>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Printable for RangeToInclusive<Idx> where T: Copy + Debug,

impl<T> SizeHint for RangeToInclusive<Idx> where T: ?Sized,

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

impl<T> SizedTypeProperties for RangeToInclusive<Idx>

impl<T, U> Into<U> for RangeToInclusive<Idx> 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 RangeToInclusive<Idx> 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 RangeToInclusive<Idx> where U: TryFrom<T>,

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