pub struct RangeInclusive<Idx> {
pub start: Idx,
pub last: Idx,
}Expand description
A range bounded inclusively below and above.
The RangeInclusive contains all values with x >= start
and x <= last. It is empty unless start <= last.
§Examples
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());§Edition notes
It is planned that the syntax start..=last will construct this
type in a future edition, but it does not do so today.
Fields§
§start: IdxThe lower bound of the range (inclusive).
last: IdxThe upper bound of the range (inclusive).
Implementations§
Source§impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx>
impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx>
1.95.0 (const: unstable) · Sourcepub fn contains<U>(&self, item: &U) -> bool
pub fn contains<U>(&self, item: &U) -> bool
Returns true if item is contained in the range.
§Examples
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));1.95.0 (const: unstable) · Sourcepub fn is_empty(&self) -> boolwhere
Idx: PartialOrd,
pub fn is_empty(&self) -> boolwhere
Idx: PartialOrd,
Returns true if the range contains no items.
§Examples
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:
Source§impl<Idx: Step> RangeInclusive<Idx>
impl<Idx: Step> RangeInclusive<Idx>
1.95.0 · Sourcepub fn iter(&self) -> RangeInclusiveIter<Idx> ⓘ
pub fn iter(&self) -> RangeInclusiveIter<Idx> ⓘ
Creates an iterator over the elements within this range.
Shorthand for .clone().into_iter()
§Examples
Trait Implementations§
1.95.0 · Source§impl<Idx: Clone> Clone for RangeInclusive<Idx>
impl<Idx: Clone> Clone for RangeInclusive<Idx>
Source§fn clone(&self) -> RangeInclusive<Idx>
fn clone(&self) -> RangeInclusive<Idx>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)where
Self:,
fn clone_from(&mut self, source: &Self)where
Self:,
source. Read more1.95.0 · Source§impl<Idx: Debug> Debug for RangeInclusive<Idx>
impl<Idx: Debug> Debug for RangeInclusive<Idx>
1.95.0 (const: unstable) · Source§impl<T> From<RangeInclusive<T>> for RangeInclusive<T>
impl<T> From<RangeInclusive<T>> for RangeInclusive<T>
Source§fn from(value: RangeInclusive<T>) -> Self
fn from(value: RangeInclusive<T>) -> Self
1.95.0 (const: unstable) · Source§impl<T> From<RangeInclusive<T>> for RangeInclusive<T>
impl<T> From<RangeInclusive<T>> for RangeInclusive<T>
Source§fn from(value: RangeInclusive<T>) -> Self
fn from(value: RangeInclusive<T>) -> Self
Source§impl GetDisjointMutIndex for RangeInclusive<usize>
impl GetDisjointMutIndex for RangeInclusive<usize>
Source§fn is_in_bounds(&self, len: usize) -> bool
fn is_in_bounds(&self, len: usize) -> bool
get_disjoint_mut_helpers)true if self is in bounds for len slice elements.Source§fn is_overlapping(&self, other: &Self) -> bool
fn is_overlapping(&self, other: &Self) -> bool
get_disjoint_mut_helpers)1.95.0 · Source§impl<Idx: Hash> Hash for RangeInclusive<Idx>
impl<Idx: Hash> Hash for RangeInclusive<Idx>
Source§impl<T> IntoBounds<T> for RangeInclusive<T>
impl<T> IntoBounds<T> for RangeInclusive<T>
1.95.0 · Source§impl<A: Step> IntoIterator for RangeInclusive<A>
impl<A: Step> IntoIterator for RangeInclusive<A>
1.95.0 · Source§impl<Idx: PartialEq> PartialEq for RangeInclusive<Idx>
impl<Idx: PartialEq> PartialEq for RangeInclusive<Idx>
1.95.0 (const: unstable) · Source§impl<T> RangeBounds<T> for RangeInclusive<&T>
If you need to use this implementation where T is unsized,
consider using the RangeBounds impl for a 2-tuple of Bound<&T>,
i.e. replace start..=end with (Bound::Included(start), Bound::Included(end)).
impl<T> RangeBounds<T> for RangeInclusive<&T>
If you need to use this implementation where T is unsized,
consider using the RangeBounds impl for a 2-tuple of Bound<&T>,
i.e. replace start..=end with (Bound::Included(start), Bound::Included(end)).
1.95.0 (const: unstable) · Source§impl<T> RangeBounds<T> for RangeInclusive<T>
impl<T> RangeBounds<T> for RangeInclusive<T>
1.95.0 (const: unstable) · Source§impl<T> SliceIndex<[T]> for RangeInclusive<usize>
impl<T> SliceIndex<[T]> for RangeInclusive<usize>
Source§fn get(self, slice: &[T]) -> Option<&[T]>
fn get(self, slice: &[T]) -> Option<&[T]>
slice_index_methods)Source§fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>
slice_index_methods)Source§unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]
unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]
slice_index_methods)Source§unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]
slice_index_methods)Source§impl SliceIndex<ByteStr> for RangeInclusive<usize>
impl SliceIndex<ByteStr> for RangeInclusive<usize>
Source§fn get(self, slice: &ByteStr) -> Option<&Self::Output>
fn get(self, slice: &ByteStr) -> Option<&Self::Output>
slice_index_methods)Source§fn get_mut(self, slice: &mut ByteStr) -> Option<&mut Self::Output>
fn get_mut(self, slice: &mut ByteStr) -> Option<&mut Self::Output>
slice_index_methods)Source§unsafe fn get_unchecked(self, slice: *const ByteStr) -> *const Self::Output
unsafe fn get_unchecked(self, slice: *const ByteStr) -> *const Self::Output
slice_index_methods)Source§unsafe fn get_unchecked_mut(self, slice: *mut ByteStr) -> *mut Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut ByteStr) -> *mut Self::Output
slice_index_methods)1.95.0 (const: unstable) · Source§impl SliceIndex<str> for RangeInclusive<usize>
impl SliceIndex<str> for RangeInclusive<usize>
Source§fn get(self, slice: &str) -> Option<&Self::Output>
fn get(self, slice: &str) -> Option<&Self::Output>
slice_index_methods)Source§fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output>
fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output>
slice_index_methods)Source§unsafe fn get_unchecked(self, slice: *const str) -> *const Self::Output
unsafe fn get_unchecked(self, slice: *const str) -> *const Self::Output
slice_index_methods)Source§unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut Self::Output
slice_index_methods)