From: Chris Gregory Date: Thu, 30 May 2019 21:46:53 +0000 (-0500) Subject: Add Bound::cloned() X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=333e1ca319636d23983de1f8ea2c102aae731c54;p=rust.git Add Bound::cloned() --- 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 { Unbounded, } +impl Bound<&T> { + /// Map a `Bound<&T>` to a `Bound` 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 { + 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`.