pub struct RangeFrom<Idx> {
pub start: Idx,
}
new_range_api
#125687)Expand description
A range only bounded inclusively below (start..
).
The RangeFrom
start..
contains all values with x >= start
.
Note: Overflow in the Iterator
implementation (when the contained
data type reaches its numerical limit) is allowed to panic, wrap, or
saturate. This behavior is defined by the implementation of the Step
trait. For primitive integers, this follows the normal rules, and respects
the overflow checks profile (panic in debug, wrap in release). Note also
that overflow happens earlier than you might assume: the overflow happens
in the call to next
that yields the maximum value, as the range must be
set to a state to yield the next value.
§Examples
The start..
syntax is a RangeFrom
:
#![feature(new_range_api)]
use core::range::RangeFrom;
assert_eq!(RangeFrom::from(2..), core::range::RangeFrom { start: 2 });
assert_eq!(2 + 3 + 4, RangeFrom::from(2..).into_iter().take(3).sum());
RunFields§
§start: Idx
new_range_api
#125687)The lower bound of the range (inclusive).
Implementations§
source§impl<Idx: Step> RangeFrom<Idx>
impl<Idx: Step> RangeFrom<Idx>
sourcepub fn iter(&self) -> IterRangeFrom<Idx> ⓘ
🔬This is a nightly-only experimental API. (new_range_api
#125687)
pub fn iter(&self) -> IterRangeFrom<Idx> ⓘ
new_range_api
#125687)Create an iterator over the elements within this range.
Shorthand for .clone().into_iter()
§Examples
#![feature(new_range_api)]
use core::range::RangeFrom;
let mut i = RangeFrom::from(3..).iter().map(|n| n*n);
assert_eq!(i.next(), Some(9));
assert_eq!(i.next(), Some(16));
assert_eq!(i.next(), Some(25));
Runsource§impl<Idx: PartialOrd<Idx>> RangeFrom<Idx>
impl<Idx: PartialOrd<Idx>> RangeFrom<Idx>
sourcepub fn contains<U>(&self, item: &U) -> bool
🔬This is a nightly-only experimental API. (new_range_api
#125687)
pub fn contains<U>(&self, item: &U) -> bool
new_range_api
#125687)Returns true
if item
is contained in the range.
§Examples
#![feature(new_range_api)]
use core::range::RangeFrom;
assert!(!RangeFrom::from(3..).contains(&2));
assert!( RangeFrom::from(3..).contains(&3));
assert!( RangeFrom::from(3..).contains(&1_000_000_000));
assert!( RangeFrom::from(0.0..).contains(&0.5));
assert!(!RangeFrom::from(0.0..).contains(&f32::NAN));
assert!(!RangeFrom::from(f32::NAN..).contains(&0.5));
RunTrait Implementations§
source§impl<A: Step> IntoIterator for RangeFrom<A>
impl<A: Step> IntoIterator for RangeFrom<A>
source§impl<Idx: PartialEq> PartialEq for RangeFrom<Idx>
impl<Idx: PartialEq> PartialEq for RangeFrom<Idx>
source§impl<T> RangeBounds<T> for RangeFrom<&T>
impl<T> RangeBounds<T> for RangeFrom<&T>
source§impl<T> RangeBounds<T> for RangeFrom<T>
impl<T> RangeBounds<T> for RangeFrom<T>
source§impl<T> SliceIndex<[T]> for RangeFrom<usize>
impl<T> SliceIndex<[T]> for RangeFrom<usize>
source§fn get(self, slice: &[T]) -> Option<&[T]>
fn get(self, slice: &[T]) -> Option<&[T]>
slice_index_methods
)source§fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>
slice_index_methods
)source§unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]
unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]
slice_index_methods
)slice
pointer
is undefined behavior even if the resulting pointer is not used.source§unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]
slice_index_methods
)slice
pointer
is undefined behavior even if the resulting pointer is not used.source§impl SliceIndex<str> for RangeFrom<usize>
impl SliceIndex<str> for RangeFrom<usize>
source§fn get(self, slice: &str) -> Option<&Self::Output>
fn get(self, slice: &str) -> Option<&Self::Output>
slice_index_methods
)source§fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output>
fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output>
slice_index_methods
)source§unsafe fn get_unchecked(self, slice: *const str) -> *const Self::Output
unsafe fn get_unchecked(self, slice: *const str) -> *const Self::Output
slice_index_methods
)slice
pointer
is undefined behavior even if the resulting pointer is not used.source§unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut Self::Output
slice_index_methods
)slice
pointer
is undefined behavior even if the resulting pointer is not used.