about summary refs log tree commit diff
path: root/src/libcore/ops
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-06-06 22:39:09 +0200
committerGitHub <noreply@github.com>2019-06-06 22:39:09 +0200
commit654854fdb56ca204bab6b399bf59a8d753e2c13c (patch)
tree5dd54e15d68f2e2d1d0c6ea6c84f92774f18b88d /src/libcore/ops
parent8b36867093fb774bcbd9f787cbc470a5f44c1310 (diff)
parentc1bc8f11cb36cade87422b91a0bdec1fe8b5af41 (diff)
downloadrust-654854fdb56ca204bab6b399bf59a8d753e2c13c.tar.gz
rust-654854fdb56ca204bab6b399bf59a8d753e2c13c.zip
Rollup merge of #61376 - czipperz:bound-cloned, r=sfackler
Add Bound::cloned()

Suggested by #61356
Diffstat (limited to 'src/libcore/ops')
-rw-r--r--src/libcore/ops/range.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs
index a707f0cc062..1b4c4218cc1 100644
--- a/src/libcore/ops/range.rs
+++ b/src/libcore/ops/range.rs
@@ -696,6 +696,29 @@ 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
+    ///
+    /// ```
+    /// #![feature(bound_cloned)]
+    /// 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")]
+    pub 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`.