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