Add Bound::cloned()
This commit is contained in:
parent
0bfbaa6e8d
commit
333e1ca319
1 changed files with 22 additions and 0 deletions
|
@ -696,6 +696,28 @@ pub enum Bound<T> {
|
||||||
Unbounded,
|
Unbounded,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Clone> 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));
|
||||||
|
/// ```
|
||||||
|
#[unstable(feature = "bound_cloned", issue = 61356)]
|
||||||
|
fn cloned(&self) -> Bound<T> {
|
||||||
|
match self {
|
||||||
|
Bound::Unbounded => Bound::Unbounded,
|
||||||
|
Bound::Included(x) => Bound::Included(x.clone()),
|
||||||
|
Bound::Excluded(x) => Bound::Excluded(x.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[stable(feature = "collections_range", since = "1.28.0")]
|
#[stable(feature = "collections_range", since = "1.28.0")]
|
||||||
/// `RangeBounds` is implemented by Rust's built-in range types, produced
|
/// `RangeBounds` is implemented by Rust's built-in range types, produced
|
||||||
/// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`.
|
/// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`.
|
||||||
|
|
Loading…
Reference in a new issue