Struct RangeInclusive

struct RangeInclusive<Idx> { ... }

A range bounded inclusively below and above (start..=last).

The RangeInclusive start..=last contains all values with x >= start and x <= last. It is empty unless start <= last.

Examples

The start..=last syntax is a RangeInclusive:

#![feature(new_range_api)]
use core::range::RangeInclusive;

assert_eq!(RangeInclusive::from(3..=5), RangeInclusive { start: 3, last: 5 });
assert_eq!(3 + 4 + 5, RangeInclusive::from(3..=5).into_iter().sum());

Fields

start: Idx

The lower bound of the range (inclusive).

last: Idx

The upper bound of the range (inclusive).

Implementations

impl<Idx: PartialOrd<Idx>> RangeInclusive<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

#![feature(new_range_api)]
use core::range::RangeInclusive;

assert!(!RangeInclusive::from(3..=5).contains(&2));
assert!( RangeInclusive::from(3..=5).contains(&3));
assert!( RangeInclusive::from(3..=5).contains(&4));
assert!( RangeInclusive::from(3..=5).contains(&5));
assert!(!RangeInclusive::from(3..=5).contains(&6));

assert!( RangeInclusive::from(3..=3).contains(&3));
assert!(!RangeInclusive::from(3..=2).contains(&3));

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

Returns true if the range contains no items.

Examples

#![feature(new_range_api)]
use core::range::RangeInclusive;

assert!(!RangeInclusive::from(3..=5).is_empty());
assert!(!RangeInclusive::from(3..=3).is_empty());
assert!( RangeInclusive::from(3..=2).is_empty());

The range is empty if either side is incomparable:

#![feature(new_range_api)]
use core::range::RangeInclusive;

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

impl<Idx: Step> RangeInclusive<Idx>

fn iter(self: &Self) -> RangeInclusiveIter<Idx>

Creates an iterator over the elements within this range.

Shorthand for .clone().into_iter()

Examples

#![feature(new_range_api)]
use core::range::RangeInclusive;

let mut i = RangeInclusive::from(3..=8).iter().map(|n| n*n);
assert_eq!(i.next(), Some(9));
assert_eq!(i.next(), Some(16));
assert_eq!(i.next(), Some(25));

impl GetDisjointMutIndex for range::RangeInclusive<usize>

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

impl SliceIndex for range::RangeInclusive<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 range::RangeInclusive<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<A: Step> IntoIterator for crate::range::RangeInclusive<A>

fn into_iter(self: Self) -> <Self as >::IntoIter

impl<Idx> Freeze for RangeInclusive<Idx>

impl<Idx> RefUnwindSafe for RangeInclusive<Idx>

impl<Idx> Send for RangeInclusive<Idx>

impl<Idx> StructuralPartialEq for RangeInclusive<Idx>

impl<Idx> Sync for RangeInclusive<Idx>

impl<Idx> Unpin for RangeInclusive<Idx>

impl<Idx> UnwindSafe for RangeInclusive<Idx>

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

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

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

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

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

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

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

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

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

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

impl<T> Any for RangeInclusive<Idx>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for RangeInclusive<Idx>

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

impl<T> BorrowMut for RangeInclusive<Idx>

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

impl<T> CloneToUninit for RangeInclusive<Idx>

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

impl<T> From for RangeInclusive<Idx>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> From for RangeInclusive<T>

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

impl<T> IntoBounds for RangeInclusive<T>

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

impl<T> RangeBounds for RangeInclusive<&T>

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

impl<T> RangeBounds for RangeInclusive<T>

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

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

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

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

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