Trait std::ops::RangeBounds

1.28.0 · source ·
pub trait RangeBounds<T>where
    T: ?Sized,{
    // Required methods
    fn start_bound(&self) -> Bound<&T>;
    fn end_bound(&self) -> Bound<&T>;

    // Provided method
    fn contains<U>(&self, item: &U) -> bool
       where T: PartialOrd<U>,
             U: PartialOrd<T> + ?Sized { ... }
}
Expand description

RangeBounds 由 Rust 的内置范围类型实现,由 ..a....b..=cd..ef..=g 等范围语法生成。

Required Methods§

source

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

开始索引绑定。

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
source

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

结束索引绑定。

将结束值返回为 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§

1.35.0 · source

fn contains<U>(&self, item: &U) -> boolwhere T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

如果范围中包含 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§

source§

impl<'a, T> RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>)where T: 'a + ?Sized,

source§

impl<T> RangeBounds<T> for (Bound<T>, Bound<T>)

source§

impl<T> RangeBounds<T> for Range<&T>

source§

impl<T> RangeBounds<T> for Range<T>

source§

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

source§

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

source§

impl<T> RangeBounds<T> for RangeFullwhere T: ?Sized,

source§

impl<T> RangeBounds<T> for RangeInclusive<&T>

source§

impl<T> RangeBounds<T> for RangeInclusive<T>

source§

impl<T> RangeBounds<T> for RangeTo<&T>

source§

impl<T> RangeBounds<T> for RangeTo<T>

source§

impl<T> RangeBounds<T> for RangeToInclusive<&T>

source§

impl<T> RangeBounds<T> for RangeToInclusive<T>