# Enum core::ops::Bound
1.17.0[−][src]

    pub enum Bound<T> {
        Included(T),
        Excluded(T),
        Unbounded,
    }

Expand description

An endpoint of a range of keys.

## Examples

`Bound`s 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));

Run

Using a tuple of `Bound`s 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());

Run

## Variants

`Included(T)`

An inclusive bound.

### Tuple Fields of Included

`0: T`
`Excluded(T)`

An exclusive bound.

### Tuple Fields of Excluded

`0: T`
`Unbounded`

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

## Implementations

[src]

### impl<T> Bound<T>

[src]

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

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

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

[src]

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

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

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

[src]

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

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

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

    #![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
[src]

### impl<T: Clone> Bound<&T>

1.55.0[src]

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

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

##### 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

[src]

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

[src]

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

Returns a copy of the value. Read more

1.0.0[src]

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

Performs copy-assignment from `source`. Read more

[src]

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

[src]

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

Formats the value using the given formatter. Read more

[src]

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

[src]

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

Feeds this value into the given `Hasher`. Read more

1.3.0[src]

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

Feeds a slice of this type into the given `Hasher`. Read more

[src]

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

[src]

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

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

[src]

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

This method tests for `!=`.

[src]

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

[src]

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

[src]

### impl<T> StructuralEq for Bound<T>

[src]

### 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

[src]

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

[src]

#### pub fn type_id(&Self) -> TypeId

Gets the `TypeId` of `self`. Read more

[src]

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

[src]

#### pub fn borrow(&Self) -> &T

Immutably borrows from an owned value. Read more

[src]

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

[src]

#### pub fn borrow_mut(&mut Self) -> &mut T

Mutably borrows from an owned value. Read more

[src]

### impl<T> From<T> for T

[src]

#### pub fn from(T) -> T

Performs the conversion.

[src]

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

[src]

#### pub fn into(Self) -> U

Performs the conversion.

[src]

### impl<T, U> TryFrom<U> for T where
U: Into<T>,

#### type Error = Infallible

The type returned in the event of a conversion error.

[src]

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

Performs the conversion.

[src]

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

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

The type returned in the event of a conversion error.

[src]

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

Performs the conversion.