Skip to content

Commit 333e1ca

Browse files
committed
Add Bound::cloned()
1 parent 0bfbaa6 commit 333e1ca

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/libcore/ops/range.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,28 @@ pub enum Bound<T> {
696696
Unbounded,
697697
}
698698

699+
impl<T: Clone> Bound<&T> {
700+
/// Map a `Bound<&T>` to a `Bound<T>` by cloning the contents of the bound.
701+
///
702+
/// # Examples
703+
///
704+
/// ```
705+
/// use std::ops::Bound::*;
706+
/// use std::ops::RangeBounds;
707+
///
708+
/// assert_eq!((1..12).start_bound(), Included(&1));
709+
/// assert_eq!((1..12).start_bound().cloned(), Included(1));
710+
/// ```
711+
#[unstable(feature = "bound_cloned", issue = 61356)]
712+
fn cloned(&self) -> Bound<T> {
713+
match self {
714+
Bound::Unbounded => Bound::Unbounded,
715+
Bound::Included(x) => Bound::Included(x.clone()),
716+
Bound::Excluded(x) => Bound::Excluded(x.clone()),
717+
}
718+
}
719+
}
720+
699721
#[stable(feature = "collections_range", since = "1.28.0")]
700722
/// `RangeBounds` is implemented by Rust's built-in range types, produced
701723
/// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`.

0 commit comments

Comments
 (0)