Struct ::std::ops::RangeToInclusive

Type for an inclusive range expression ..=end.

Examples

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

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

Ranges can contain any type:

let range = ..='f';
assert_eq!(range.end, 'f');
range.end = 'g';
assert_eq!(range.end, 'g');

Examples

use rune::runtime::RangeToInclusive;

let end = rune::to_value(10)?;
let _ = RangeToInclusive::new(end);

Methods

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 = ..=10;

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

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

Protocols

protocol get
let output = value.end

Allows a get operation to work.

protocol set
value.end = input

Allows a set operation to work.

protocol partial_eq
if value == b { }

Test the range for partial equality.

Examples

let range = ..='e';
assert!(range == (..='e'));
assert!(range != (..='f'));

let range = ..=2.0;
assert!(range == (..=2.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 = ..='e';
assert!(eq(range, ..='e'));
assert!(!eq(range, ..='f'));
protocol partial_cmp
if value < b { }

Test the range for partial ordering.

Examples

assert!((..='a') < (..='b'));
assert!((..='d') > (..='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);