Trait core::ops::RangeBounds1.28.0[][src]

pub trait RangeBounds<T: ?Sized> {
    fn start_bound(&self) -> Bound<&T>;
fn end_bound(&self) -> Bound<&T>; fn contains<U: ?Sized>(&self, item: &U) -> bool
    where
        T: PartialOrd<U>,
        U: PartialOrd<T>
, { ... } }
Expand description

RangeBounds 由 Rust 的内置范围类型实现,该范围类型由范围语法 (例如 ..a....b..=cd..ef..=g) 产生。

Required methods

开始索引绑定。

Bound 形式返回起始值。

Examples

use std::ops::Bound::*;
use std::ops::RangeBounds;

assert_eq!((..10).start_bound(), Unbounded);
assert_eq!((3..10).start_bound(), Included(&3));
Run

结束索引绑定。

将结束值返回为 Bound

Examples

use std::ops::Bound::*;
use std::ops::RangeBounds;

assert_eq!((3..).end_bound(), Unbounded);
assert_eq!((3..10).end_bound(), Excluded(&10));
Run

Provided methods

如果范围中包含 item,则返回 true

Examples

assert!( (3..5).contains(&4));
assert!(!(3..5).contains(&2));

assert!( (0.0..1.0).contains(&0.5));
assert!(!(0.0..1.0).contains(&f32::NAN));
assert!(!(0.0..f32::NAN).contains(&0.5));
assert!(!(f32::NAN..1.0).contains(&0.5));
Run

Implementors