Range in std::range - Rust (original) (raw)

pub struct Range<Idx> {
    pub start: Idx,
    pub end: Idx,
}

🔬This is a nightly-only experimental API. (new_range_api #125687)

Expand description

A (half-open) range bounded inclusively below and exclusively above (start..end in a future edition).

The range start..end contains all values with start <= x < end. It is empty if start >= end.

§Examples

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

assert_eq!(Range::from(3..5), Range { start: 3, end: 5 });
assert_eq!(3 + 4 + 5, Range::from(3..6).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 (exclusive).

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::Range;

let mut i = Range::from(3..9).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

🔬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::Range;

assert!(!Range::from(3..5).contains(&2));
assert!( Range::from(3..5).contains(&3));
assert!( Range::from(3..5).contains(&4));
assert!(!Range::from(3..5).contains(&5));

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

assert!( Range::from(0.0..1.0).contains(&0.5));
assert!(!Range::from(0.0..1.0).contains(&f32::NAN));
assert!(!Range::from(0.0..f32::NAN).contains(&0.5));
assert!(!Range::from(f32::NAN..1.0).contains(&0.5));

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::Range;

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

The range is empty if either side is incomparable:

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

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

Source§

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§

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§

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§