Enum Bound

enum Bound<T>

An endpoint of a range of keys.

Examples

Bounds are range endpoints:

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

Using a tuple of Bounds as an argument to BTreeMap::range. Note that in most cases, it's better to use range syntax (1..5) instead.

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());

Variants

Included(T)

An inclusive bound.

Excluded(T)

An exclusive bound.

Unbounded

An infinite endpoint. Indicates that there is no bound in this direction.

Implementations

impl<T> Bound<T>

const fn as_ref(self: &Self) -> Bound<&T>

Converts from &Bound<T> to Bound<&T>.

const fn as_mut(self: &mut Self) -> Bound<&mut T>

Converts from &mut Bound<T> to Bound<&mut T>.

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

Maps a Bound<T> to a Bound<U> by applying a function to the contained value (including both Included and Excluded), returning a Bound of the same kind.

Examples

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

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

assert_eq!(bound_string.map(|s| s.len()), Included(13));
use std::ops::Bound;
use Bound::*;

let unbounded_string: Bound<String> = Unbounded;

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

impl<T: Clone> Bound<&T>

const fn cloned(self: Self) -> Bound<T>
where
    T: ~const Clone

Map a Bound<&T> to a Bound<T> by cloning the contents of the bound.

Examples

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

let a1 = String::from("a");
let (a2, a3, a4) = (a1.clone(), a1.clone(), a1.clone());

assert_eq!(Included(&a1), (a2..).start_bound());
assert_eq!(Included(a3), (a4..).start_bound().cloned());

impl<T: Copy> Bound<&T>

const fn copied(self: Self) -> Bound<T>

Map a Bound<&T> to a Bound<T> by copying the contents of the bound.

Examples

#![feature(bound_copied)]

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

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

impl<T> Any for Bound<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Bound<T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Bound<T>

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

impl<T> CloneToUninit for Bound<T>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> Freeze for Bound<T>

impl<T> From for Bound<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> RefUnwindSafe for Bound<T>

impl<T> Send for Bound<T>

impl<T> StructuralPartialEq for Bound<T>

impl<T> Sync for Bound<T>

impl<T> Unpin for Bound<T>

impl<T> UnsafeUnpin for Bound<T>

impl<T> UnwindSafe for Bound<T>

impl<T, U> Into for Bound<T>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Bound<T>

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

impl<T, U> TryInto for Bound<T>

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

impl<T: $crate::fmt::Debug> Debug for Bound<T>

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

impl<T: $crate::hash::Hash> Hash for Bound<T>

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

impl<T: $crate::marker::Copy> Copy for Bound<T>

impl<T: ~const $crate::clone::Clone> Clone for Bound<T>

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

impl<T: ~const $crate::cmp::Eq> Eq for Bound<T>

impl<T: ~const $crate::cmp::PartialEq> PartialEq for Bound<T>

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