Enum core::ops::Bound

1.17.0 · source ·
pub enum Bound<T> {
    Included(T),
    Excluded(T),
    Unbounded,
}
Expand description

一系列键的端点。

Examples

边界是范围端点:

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

assert_eq!((..100).start_bound(), Unbounded);
assert_eq!((1..12).start_bound(), Included(&1));
assert_eq!((1..12).end_bound(), Excluded(&12));
Run

使用 Bounds 的元组作为 BTreeMap::range 的参数。 请注意,在大多数情况下,最好改用范围语法 (1..5)。

use std::collections::BTreeMap;
use std::ops::Bound::{Excluded, Included, Unbounded};

let mut map = BTreeMap::new();
map.insert(3, "a");
map.insert(5, "b");
map.insert(8, "c");

for (key, value) in map.range((Excluded(3), Included(8))) {
    println!("{key}: {value}");
}

assert_eq!(Some((&3, &"a")), map.range((Unbounded, Included(5))).next());
Run

Variants§

§

Included(T)

包容性范围。

§

Excluded(T)

排他性约束。

§

Unbounded

无限端点。指示此方向没有界限。

Implementations§

source§

impl<T> Bound<T>

1.65.0 · source

pub fn as_ref(&self) -> Bound<&T>

&Bound<T> 转换为 Bound<&T>

source

pub fn as_mut(&mut self) -> Bound<&mut T>

🔬This is a nightly-only experimental API. (bound_as_ref #80996)

&mut Bound<T> 转换为 Bound<&mut T>

source

pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Bound<U>

🔬This is a nightly-only experimental API. (bound_map #86026)

映射一个 Bound 通过将函数应用于包含的值 (包括 IncludedExcluded),返回相同类型的 Bound

Examples
#![feature(bound_map)]
use std::ops::Bound::*;

let bound_string = Included("Hello, World!");

assert_eq!(bound_string.map(|s| s.len()), Included(13));
Run
#![feature(bound_map)]
use std::ops::Bound;
use Bound::*;

let unbounded_string: Bound<String> = Unbounded;

assert_eq!(unbounded_string.map(|s| s.len()), Unbounded);
Run
source§

impl<T: Clone> Bound<&T>

1.55.0 · source

pub fn cloned(self) -> Bound<T>

Map 通过克隆绑定的内容将 Bound<&T> 更改为 Bound<T>

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

assert_eq!((1..12).start_bound(), Included(&1));
assert_eq!((1..12).start_bound().cloned(), Included(1));
Run

Trait Implementations§

source§

impl<T: Clone> Clone for Bound<T>

source§

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

返回值的副本。 Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

source 执行复制分配。 Read more
source§

impl<T: Debug> Debug for Bound<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

使用给定的格式化程序格式化该值。 Read more
source§

impl<T: Hash> Hash for Bound<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

将该值输入给定的 HasherRead more
1.3.0 · source§

fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)where Self: Sized,

将这种类型的切片送入给定的 Hasher 中。 Read more
source§

impl<T: PartialEq> PartialEq<Bound<T>> for Bound<T>

source§

fn eq(&self, other: &Bound<T>) -> bool

此方法测试 selfother 值是否相等,并由 == 使用。
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

此方法测试 !=。 默认实现几乎总是足够的,并且不应在没有充分理由的情况下被覆盖。
source§

impl<T: Copy> Copy for Bound<T>

source§

impl<T: Eq> Eq for Bound<T>

source§

impl<T> StructuralEq for Bound<T>

source§

impl<T> StructuralPartialEq for Bound<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Bound<T>where T: RefUnwindSafe,

§

impl<T> Send for Bound<T>where T: Send,

§

impl<T> Sync for Bound<T>where T: Sync,

§

impl<T> Unpin for Bound<T>where T: Unpin,

§

impl<T> UnwindSafe for Bound<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

获取 selfTypeIdRead more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

从拥有的值中一成不变地借用。 Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

从拥有的值中借用。 Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

返回未更改的参数。

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

调用 U::from(self)

也就是说,这种转换是 From<T> for U 实现选择执行的任何操作。

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

发生转换错误时返回的类型。
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

执行转换。
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

发生转换错误时返回的类型。
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

执行转换。