Enum Bound

pub 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) -> Bound<&T>

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

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

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

fn map<U, F: FnOnce(T) -> U>(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) -> 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) -> 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));

Trait Implementations

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

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

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

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

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

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

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

fn clone(&self) -> Self

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

fn assert_fields_are_eq(&self)

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

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

Auto Trait Implementations

impl<T> Freeze for Bound<T> where T: Freeze + Freeze,

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

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

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

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

impl<T> UnsafeUnpin for Bound<T> where T: UnsafeUnpin + UnsafeUnpin,

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

Blanket Implementations

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Bound<T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Bound<T> where T: ?Sized,

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

impl<T> CloneToUninit for Bound<T> where T: Clone,

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

impl<T> From<T> for Bound<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Printable for Bound<T> where T: Copy + Debug,

impl<T> SizeHint for Bound<T> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Bound<T>

impl<T, U> Into<U> for Bound<T> where U: From<T>,

fn into(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<U> for Bound<T> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Bound<T> where U: TryFrom<T>,

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