RangeInclusive in core::range - Rust (original) (raw)

Struct RangeInclusive

Source

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 >= startand 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).

Source§

Source

🔬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));

Source

🔬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());

Source§

Source

🔬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));

Source§

Source§

Source§

Source§

Converts to this type from the input type.

Source§

Source§

Converts to this type from the input type.

Source§

Source§

🔬This is a nightly-only experimental API. (get_disjoint_mut_helpers)

Returns true if self is in bounds for len slice elements.

Source§

🔬This is a nightly-only experimental API. (get_disjoint_mut_helpers)

Returns true if self overlaps with other. Read more

Source§

Source§

Source§

🔬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

Source§

🔬This is a nightly-only experimental API. (range_into_bounds #136903)

Compute the intersection of self and other. Read more

Source§

Source§

The type of the elements being iterated over.

Source§

Which kind of iterator are we turning this into?

Source§

Creates an iterator from a value. Read more

Source§

Source§

Tests for self and other values to be equal, and is used by ==.

1.0.0 · Source§

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Source§

Source§

Source§

1.35.0 · Source§

Returns true if item is contained in the range. Read more

Source§

🔬This is a nightly-only experimental API. (range_bounds_is_empty #137300)

Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more

Source§

Source§

Source§

1.35.0 · Source§

Returns true if item is contained in the range. Read more

Source§

🔬This is a nightly-only experimental API. (range_bounds_is_empty #137300)

Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more

Source§

Source§

The output type returned by methods.

Source§

🔬This is a nightly-only experimental API. (slice_index_methods)

Returns a shared reference to the output at this location, if in bounds.

Source§

🔬This is a nightly-only experimental API. (slice_index_methods)

Returns a mutable reference to the output at this location, if in bounds.

Source§

🔬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

Source§

🔬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

Source§

🔬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.

Source§

🔬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.

Source§

Source§

The output type returned by methods.

Source§

🔬This is a nightly-only experimental API. (slice_index_methods)

Returns a shared reference to the output at this location, if in bounds.

Source§

🔬This is a nightly-only experimental API. (slice_index_methods)

Returns a mutable reference to the output at this location, if in bounds.

Source§

🔬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

Source§

🔬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

Source§

🔬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.

Source§

🔬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.

Source§

Source§

Source§