Struct ::std::ops::RangeFrom

Type for a from range expression start...

Examples

let range = 0..;

assert!(!range.contains(-10));
assert!(range.contains(5));
assert!(range.contains(10));
assert!(range.contains(20));

assert!(range is std::ops::RangeFrom);

Ranges can contain any type:

let range = 'a'..;
assert_eq!(range.start, 'a');
range.start = 'b';
assert_eq!(range.start, 'b');

Certain ranges can be used as iterators:

let range = 'a'..;
assert_eq!(range.iter().take(5).collect::<Vec>(), ['a', 'b', 'c', 'd', 'e']);

Rust examples

use rune::runtime::RangeFrom;

let start = rune::to_value(1)?;
let _ = RangeFrom::new(start);

Methods

fn iter(self) -> Iterator

Iterate over the range.

Panics

This panics if the range is not a well-defined range.

Examples

let range = 'a'..;
assert_eq!(range.iter().take(5).collect::<Vec>(), ['a', 'b', 'c', 'd', 'e']);

Cannot construct an iterator over floats:

let range = 1.0..;
range.iter()
fn contains(self, value) -> bool

Test if the range contains the given value.

The check is performed using the [PARTIAL_CMP] protocol.

Examples

let range = 0..;

assert!(!range.contains(-10));
assert!(range.contains(5));
assert!(range.contains(10));
assert!(range.contains(20));

assert!(range is std::ops::RangeFrom);

Protocols

protocol get
let output = value.start

Allows a get operation to work.

protocol set
value.start = input

Allows a set operation to work.

protocol into_iter
for item in value { }

Build an iterator over the range.

Panics

This panics if the range is not a well-defined range.

Examples

let vec = [];

for value in 'a'.. {
   vec.push(value);

   if value == 'e' {
      break;
   }
}

assert_eq!(vec, ['a', 'b', 'c', 'd', 'e']);

Cannot construct an iterator over floats:

let range = 1.0..;

for value in 1.0 .. {
}
protocol partial_eq
if value == b { }

Test the range for partial equality.

Examples

let range = 'a'..;
assert!(range == ('a'..));
assert!(range != ('b'..));

let range = 1.0..;
assert!(range == (1.0..));
assert!(range != (f64::NAN..));
assert!((f64::NAN..) != (f64::NAN..));
protocol eq
if value == b { }

Test the range for total equality.

Examples

use std::ops::eq;

let range = 'a'..;
assert!(eq(range, 'a'..));
assert!(!eq(range, 'b'..));
protocol partial_cmp
if value < b { }

Test the range for partial ordering.

Examples

assert!(('a'..) < ('b'..));
assert!(('c'..) > ('b'..));
assert!(!((f64::NAN..) > (f64::INFINITY..)));
assert!(!((f64::NAN..) < (f64::INFINITY..)));
protocol cmp
if value < b { }

Test the range for total ordering.

Examples

use std::ops::cmp;
use std::cmp::Ordering;

assert_eq!(cmp('a'.., 'b'..), Ordering::Less);
assert_eq!(cmp('c'.., 'b'..), Ordering::Greater);