Struct RangeFrom

pub struct RangeFrom<Idx> { pub start: Idx }

A range only bounded inclusively below.

The RangeFrom contains all values with x >= start.

Note: Overflow in the IntoIterator 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). Unlike its legacy counterpart, the iterator will only panic after yielding the maximum value when overflow checks are enabled.

Examples

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

Edition notes

It is planned that the syntax start.. will construct this type in a future edition, but it does not do so today.

Fields

start: Idx

The lower bound of the range (inclusive).

Implementations

impl<Idx: PartialOrd<Idx>> RangeFrom<Idx>

const fn contains<U>(&self, item: &U) -> bool
where
    Idx: ~const PartialOrd<U>,
    U: ?Sized + ~const PartialOrd<Idx>,

Returns true if item is contained in the range.

Examples

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

impl<Idx: Step> RangeFrom<Idx>

fn iter(&self) -> RangeFromIter<Idx>

Creates an iterator over the elements within this range.

Shorthand for .clone().into_iter()

Examples

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

Trait Implementations

impl SliceIndex<ByteStr> for RangeFrom<usize>

type Output = ByteStr;
fn get(self, slice: &ByteStr) -> Option<&Self::Output>
fn get_mut(self, slice: &mut ByteStr) -> Option<&mut Self::Output>
unsafe fn get_unchecked(self, slice: *const ByteStr) -> *const Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut ByteStr) -> *mut Self::Output
fn index(self, slice: &ByteStr) -> &Self::Output
fn index_mut(self, slice: &mut ByteStr) -> &mut Self::Output

impl SliceIndex<str> for RangeFrom<usize>

type Output = str;
fn get(self, slice: &str) -> Option<&Self::Output>
fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output>
unsafe fn get_unchecked(self, slice: *const str) -> *const Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut Self::Output
fn index(self, slice: &str) -> &Self::Output
fn index_mut(self, slice: &mut str) -> &mut Self::Output

impl<A: Step> IntoIterator for RangeFrom<A>

type Item = A;
type IntoIter = RangeFromIter<A>;
fn into_iter(self) -> Self::IntoIter

impl<Idx: Copy> Copy for RangeFrom<Idx>

impl<Idx: Debug> Debug for RangeFrom<Idx>

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

impl<Idx: Hash> Hash for RangeFrom<Idx>

fn hash<__H: Hasher>(&self, state: &mut __H)

impl<Idx: PartialEq> StructuralPartialEq for RangeFrom<Idx>

impl<Idx: ~const Clone> Clone for RangeFrom<Idx>

fn clone(&self) -> RangeFrom<Idx>

impl<Idx: ~const Eq> Eq for RangeFrom<Idx>

fn assert_fields_are_eq(&self)

impl<Idx: ~const PartialEq> PartialEq for RangeFrom<Idx>

fn eq(&self, other: &RangeFrom<Idx>) -> bool

impl<T> From<RangeFrom<T>> for RangeFrom<T>

fn from(value: RangeFrom<T>) -> Self

impl<T> IntoBounds<T> for RangeFrom<T>

fn into_bounds(self) -> (Bound<T>, Bound<T>)

impl<T> OneSidedRange<T> for RangeFrom<T> where Self: RangeBounds<T>,

fn bound(self) -> (OneSidedRangeBound, T)

impl<T> RangeBounds<T> for RangeFrom<&T>

fn start_bound(&self) -> Bound<&T>
fn end_bound(&self) -> Bound<&T>

impl<T> RangeBounds<T> for RangeFrom<T>

fn start_bound(&self) -> Bound<&T>
fn end_bound(&self) -> Bound<&T>

impl<T> SliceIndex<[T]> for RangeFrom<usize>

type Output = [T];
fn get(self, slice: &[T]) -> Option<&[T]>
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>
unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]
fn index(self, slice: &[T]) -> &[T]
fn index_mut(self, slice: &mut [T]) -> &mut [T]

Auto Trait Implementations

impl<Idx> Freeze for RangeFrom<Idx> where Idx: Freeze,

impl<Idx> RefUnwindSafe for RangeFrom<Idx> where Idx: RefUnwindSafe,

impl<Idx> Send for RangeFrom<Idx> where Idx: Send,

impl<Idx> Sync for RangeFrom<Idx> where Idx: Sync,

impl<Idx> Unpin for RangeFrom<Idx> where Idx: Unpin,

impl<Idx> UnsafeUnpin for RangeFrom<Idx> where Idx: UnsafeUnpin,

impl<Idx> UnwindSafe for RangeFrom<Idx> where Idx: UnwindSafe,

Blanket Implementations

impl<T> Any for RangeFrom<Idx> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for RangeFrom<Idx> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for RangeFrom<Idx> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for RangeFrom<Idx> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for RangeFrom<Idx>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Printable for RangeFrom<Idx> where T: Copy + Debug,

impl<T> SizeHint for RangeFrom<Idx> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for RangeFrom<Idx>

impl<T, U> Into<U> for RangeFrom<Idx> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for RangeFrom<Idx> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for RangeFrom<Idx> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>