]> git.lizzy.rs Git - rust.git/commitdiff
Add Bound::cloned()
authorChris Gregory <czipperz@gmail.com>
Thu, 30 May 2019 21:46:53 +0000 (16:46 -0500)
committerChris Gregory <czipperz@gmail.com>
Thu, 30 May 2019 21:46:53 +0000 (16:46 -0500)
src/libcore/ops/range.rs

index a707f0cc0627acdd6c3cf404c0cb30e8380039b1..39bf80281c576d4b4fe3b356990c60ecbcb67c00 100644 (file)
@@ -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`.