RangeInclusive in std::range - Rust (original) (raw)
Struct RangeInclusive
pub struct RangeInclusive<Idx> {
pub start: Idx,
pub end: Idx,
}
🔬This is a nightly-only experimental API. (new_range_api
#125687)
Expand description
A range bounded inclusively below and above (start..=end
).
The RangeInclusive
start..=end
contains all values with x >= start
and x <= end
. It is empty unless start <= end
.
§Examples
The start..=end
syntax is a RangeInclusive
:
#![feature(new_range_api)]
use core::range::RangeInclusive;
assert_eq!(RangeInclusive::from(3..=5), RangeInclusive { start: 3, end: 5 });
assert_eq!(3 + 4 + 5, RangeInclusive::from(3..=5).into_iter().sum());
🔬This is a nightly-only experimental API. (new_range_api
#125687)
The lower bound of the range (inclusive).
🔬This is a nightly-only experimental API. (new_range_api
#125687)
The upper bound of the range (inclusive).
🔬This is a nightly-only experimental API. (new_range_api
#125687)
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));
🔬This is a nightly-only experimental API. (new_range_api
#125687)
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());
🔬This is a nightly-only experimental API. (new_range_api
#125687)
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));
Converts to this type from the input type.
Converts to this type from the input type.
🔬This is a nightly-only experimental API. (get_disjoint_mut_helpers
)
Returns true
if self
is in bounds for len
slice elements.
🔬This is a nightly-only experimental API. (get_disjoint_mut_helpers
)
Returns true
if self
overlaps with other
. Read more
🔬This is a nightly-only experimental API. (range_into_bounds
#136903)
Convert this range into the start and end bounds. Returns (start_bound, end_bound)
. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient, and should not be overridden without very good reason.
The output type returned by methods.
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a shared reference to the output at this location, if in bounds.
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a mutable reference to the output at this location, if in bounds.
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a shared reference to the output at this location, panicking if out of bounds.
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a mutable reference to the output at this location, panicking if out of bounds.
The output type returned by methods.
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a shared reference to the output at this location, if in bounds.
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a mutable reference to the output at this location, if in bounds.
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a pointer to the output at this location, without performing any bounds checking. Read more
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a mutable pointer to the output at this location, without performing any bounds checking. Read more
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a shared reference to the output at this location, panicking if out of bounds.
🔬This is a nightly-only experimental API. (slice_index_methods
)
Returns a mutable reference to the output at this location, panicking if out of bounds.