Skip to content

Commit 1112274

Browse files
committed
add Bound::copied
Signed-off-by: Connor Tsui <[email protected]>
1 parent b53c72f commit 1112274

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

library/core/src/ops/range.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,28 @@ impl<T> Bound<T> {
736736
}
737737
}
738738

739+
impl<T: Copy> Bound<&T> {
740+
/// Map a `Bound<&T>` to a `Bound<T>` by copying the contents of the bound.
741+
///
742+
/// # Examples
743+
///
744+
/// ```
745+
/// use std::ops::Bound::*;
746+
/// use std::ops::RangeBounds;
747+
///
748+
/// assert_eq!((1..12).start_bound(), Included(&1));
749+
/// assert_eq!((1..12).start_bound().copied(), Included(1));
750+
/// ```
751+
#[unstable(feature = "bound_copied", issue = "145966")]
752+
pub fn copied(self) -> Bound<T> {
753+
match self {
754+
Bound::Unbounded => Bound::Unbounded,
755+
Bound::Included(x) => Bound::Included(*x),
756+
Bound::Excluded(x) => Bound::Excluded(*x),
757+
}
758+
}
759+
}
760+
739761
impl<T: Clone> Bound<&T> {
740762
/// Map a `Bound<&T>` to a `Bound<T>` by cloning the contents of the bound.
741763
///

0 commit comments

Comments
 (0)