Struct std::ops::RangeTo

Overview

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

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::RangeTo;

let end = rune::to_value(1)?;
let _ = RangeTo::new(end);

Methods

fn contains(self, value: any) -> 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::RangeTo);

Trait Implementations

impl PartialEq for RangeTo
fn eq(value: any, value1: any) -> bool

Compare two values for equality.

Examples

assert_eq!(1.eq(2), false);
assert_eq!(2.eq(2), true);
assert_eq!(2.eq(1), false);
fn ne(value: any, value1: any) -> bool

Compare two values for inequality.

Examples

assert_eq!(1.ne(2), true);
assert_eq!(2.ne(2), false);
assert_eq!(2.ne(1), true);
impl Eq for RangeTo
impl PartialOrd for RangeTo
fn partial_cmp(value: any, value1: any) -> Option

Compare two values.

Examples

use std::cmp::Ordering;

assert_eq!(1.partial_cmp(2), Some(Ordering::Less));
assert_eq!(2.partial_cmp(2), Some(Ordering::Equal));
assert_eq!(2.partial_cmp(1), Some(Ordering::Greater));
fn lt(value: any, value1: any) -> bool

Tests less than (for self and other) and is used by the < operator.

Examples

assert_eq!(1.0 < 1.0, false);
assert_eq!(1.0 < 2.0, true);
assert_eq!(2.0 < 1.0, false);
fn le(value: any, value1: any) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator.

Examples

assert_eq!(1.0 <= 1.0, true);
assert_eq!(1.0 <= 2.0, true);
assert_eq!(2.0 <= 1.0, false);
fn gt(value: any, value1: any) -> bool

Tests greater than (for self and other) and is used by the > operator.

Examples

assert_eq!(1.0 > 1.0, false);
assert_eq!(1.0 > 2.0, false);
assert_eq!(2.0 > 1.0, true);
fn ge(value: any, value1: any) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator.

Examples

assert_eq!(1.0 >= 1.0, true);
assert_eq!(1.0 >= 2.0, false);
assert_eq!(2.0 >= 1.0, true);
impl Ord for RangeTo
fn cmp(value: any, value1: any) -> Ordering

Compare two values.

Examples

use std::cmp::Ordering;

assert_eq!(1.cmp(2), Ordering::Less);
assert_eq!(2.cmp(2), Ordering::Equal);
assert_eq!(2.cmp(1), Ordering::Greater);
fn min(value: any, value1: any) -> Ordering

Return the minimum of two values.

Examples

assert_eq!(1.min(2), 1);
assert_eq!(2.min(2), 2);
assert_eq!(2.min(1), 1);
fn max(value: any, value1: any) -> Ordering

Return the maximum of two values.

Examples

assert_eq!(1.max(2), 2);
assert_eq!(2.max(2), 2);
assert_eq!(2.max(1), 2);

Protocols

protocol GET end
let $out = value.end

Allows a get operation to work.

protocol SET end
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);
protocol LT
if $a < $b { }

The protocol behind the < operator.

protocol LE
if $a <= $b { }

The protocol behind the <= operator.

protocol GT
if $a > $b { }

The protocol behind the > operator.

protocol GE
if $a >= $b { }

The protocol behind the >= operator.

protocol MIN
$a.min($b)

The implementation protocol for the PartialOrd::min method.

protocol MAX
$a.max($b)

The implementation protocol for the PartialOrd::max method.