about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Gregory <czipperz@gmail.com>2019-05-30 16:46:53 -0500
committerChris Gregory <czipperz@gmail.com>2019-05-30 16:46:53 -0500
commit333e1ca319636d23983de1f8ea2c102aae731c54 (patch)
tree005d0e8edbe26393d171d10bde8f13dc2b39e207
parent0bfbaa6e8dfb509b453020740fd37c7a22882c87 (diff)
downloadrust-333e1ca319636d23983de1f8ea2c102aae731c54.tar.gz
rust-333e1ca319636d23983de1f8ea2c102aae731c54.zip
Add Bound::cloned()
-rw-r--r--src/libcore/ops/range.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs
index a707f0cc062..39bf80281c5 100644
--- a/src/libcore/ops/range.rs
+++ b/src/libcore/ops/range.rs
@@ -696,6 +696,28 @@ pub enum Bound<T> {
     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")]
 /// `RangeBounds` is implemented by Rust's built-in range types, produced
 /// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`.