Struct RangeInclusive
pub struct RangeInclusive<Idx> { pub start: Idx, pub last: Idx }
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 RangeInclusive;
assert_eq!;
assert_eq!;
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
impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx>
const fn contains<U>(&self, item: &U) -> bool where Idx: ~const PartialOrd<U>, U: ?Sized + ~const PartialOrd<Idx>,Returns
trueifitemis contained in the range.Examples
use RangeInclusive; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!;const fn is_empty(&self) -> bool where Idx: ~const PartialOrd,Returns
trueif the range contains no items.Examples
use RangeInclusive; assert!; assert!; assert!;The range is empty if either side is incomparable:
use RangeInclusive; assert!; assert!; assert!;
impl<Idx: Step> RangeInclusive<Idx>
fn iter(&self) -> RangeInclusiveIter<Idx>Creates an iterator over the elements within this range.
Shorthand for
.clone().into_iter()Examples
use RangeInclusive; let mut i = from.iter.map; assert_eq!; assert_eq!; assert_eq!;
Trait Implementations
impl Distribution<i128> for RangeInclusive<i128>
fn sample(&self, source: &mut impl Rng + ?Sized) -> i128Chooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<i16> for RangeInclusive<i16>
fn sample(&self, source: &mut impl Rng + ?Sized) -> i16Chooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<i32> for RangeInclusive<i32>
fn sample(&self, source: &mut impl Rng + ?Sized) -> i32Chooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<i64> for RangeInclusive<i64>
fn sample(&self, source: &mut impl Rng + ?Sized) -> i64Chooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<i8> for RangeInclusive<i8>
fn sample(&self, source: &mut impl Rng + ?Sized) -> i8Chooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<isize> for RangeInclusive<isize>
fn sample(&self, source: &mut impl Rng + ?Sized) -> isizeChooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<u128> for RangeInclusive<u128>
fn sample(&self, source: &mut impl Rng + ?Sized) -> u128Chooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<u16> for RangeInclusive<u16>
fn sample(&self, source: &mut impl Rng + ?Sized) -> u16Chooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<u32> for RangeInclusive<u32>
fn sample(&self, source: &mut impl Rng + ?Sized) -> u32Chooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<u64> for RangeInclusive<u64>
fn sample(&self, source: &mut impl Rng + ?Sized) -> u64Chooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<u8> for RangeInclusive<u8>
fn sample(&self, source: &mut impl Rng + ?Sized) -> u8Chooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl Distribution<usize> for RangeInclusive<usize>
fn sample(&self, source: &mut impl Rng + ?Sized) -> usizeChooses a random number within the range.
Every possible result value is equally likely. In other words, this operation uses unbiased uniform sampling.
Panics
Panics if the range is empty.
Side-channels
This implementation does not claim to be resistant against side- channel attacks. In particular, the execution time of this operation may leak information about the returned value, and not just the values of the range bounds. While this implementation tries to avoid operations with particularly data-dependent timing (such as divisions), Rust as a language has no facilities for ensuring data-independent timing, voiding all promises about side-channel- freedom.
Examples
A D20 dice roll:
use ; use RangeInclusive; let roll = from.sample; assert!; if roll == 20 else
impl GetDisjointMutIndex for RangeInclusive<usize>
fn is_in_bounds(&self, len: usize) -> boolfn is_overlapping(&self, other: &Self) -> bool
impl SliceIndex<ByteStr> for RangeInclusive<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::Outputunsafe fn get_unchecked_mut(self, slice: *mut ByteStr) -> *mut Self::Outputfn index(self, slice: &ByteStr) -> &Self::Outputfn index_mut(self, slice: &mut ByteStr) -> &mut Self::Output
impl SliceIndex<str> for RangeInclusive<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::Outputunsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut Self::Outputfn index(self, slice: &str) -> &Self::Outputfn index_mut(self, slice: &mut str) -> &mut Self::Output
impl<A: Step> IntoIterator for RangeInclusive<A>
type Item = A;type IntoIter = RangeInclusiveIter<A>;fn into_iter(self) -> Self::IntoIter
impl<Idx: Clone> Clone for RangeInclusive<Idx>
fn clone(&self) -> RangeInclusive<Idx>
impl<Idx: Copy> Copy for RangeInclusive<Idx>
impl<Idx: Debug> Debug for RangeInclusive<Idx>
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
impl<Idx: Eq> Eq for RangeInclusive<Idx>
fn assert_fields_are_eq(&self)
impl<Idx: Hash> Hash for RangeInclusive<Idx>
fn hash<__H: Hasher>(&self, state: &mut __H)
impl<Idx: PartialEq> PartialEq for RangeInclusive<Idx>
fn eq(&self, other: &RangeInclusive<Idx>) -> bool
impl<Idx: PartialEq> StructuralPartialEq for RangeInclusive<Idx>
impl<T> From<RangeInclusive<T>> for RangeInclusive<T>
fn from(value: RangeInclusive<T>) -> SelfConverts from a legacy range to a non-legacy range, potentially panicking.
Panics
If the legacy range iterator has been exhausted, this function will either panic or return an empty range.
Examples
use legacy; use RangeInclusive; let single: RangeInclusive = 0..=1; let single = from; assert_eq!; let empty: RangeInclusive = 0..=0; let empty = from; assert_eq!;# // This test requires unwinding to work. # // Disable it when unwinding isn't available. # # # #
impl<T> IntoBounds<T> for RangeInclusive<T>
fn into_bounds(self) -> (Bound<T>, Bound<T>)
impl<T> RangeBounds<T> for RangeInclusive<&T>
fn start_bound(&self) -> Bound<&T>fn end_bound(&self) -> Bound<&T>
impl<T> RangeBounds<T> for RangeInclusive<T>
fn start_bound(&self) -> Bound<&T>fn end_bound(&self) -> Bound<&T>
impl<T> SliceIndex<[T]> for RangeInclusive<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 RangeInclusive<Idx>
where
Idx: Freeze + Freeze,
impl<Idx> RefUnwindSafe for RangeInclusive<Idx>
where
Idx: RefUnwindSafe + RefUnwindSafe,
impl<Idx> Send for RangeInclusive<Idx>
where
Idx: Send + Send,
impl<Idx> Sync for RangeInclusive<Idx>
where
Idx: Sync + Sync,
impl<Idx> Unpin for RangeInclusive<Idx>
where
Idx: Unpin + Unpin,
impl<Idx> UnsafeUnpin for RangeInclusive<Idx>
where
Idx: UnsafeUnpin + UnsafeUnpin,
impl<Idx> UnwindSafe for RangeInclusive<Idx>
where
Idx: UnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for RangeInclusive<Idx>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for RangeInclusive<Idx>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for RangeInclusive<Idx>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for RangeInclusive<Idx>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for RangeInclusive<Idx>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Printable for RangeInclusive<Idx>
where
T: Copy + Debug,
impl<T> SizeHint for RangeInclusive<Idx>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for RangeInclusive<Idx>
impl<T, U> Into<U> for RangeInclusive<Idx>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for RangeInclusive<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 RangeInclusive<Idx>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>