Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add Bound::copied
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
  • Loading branch information
connortsui20 committed Aug 30, 2025
commit 1112274275be9216b42ef2f27b1e85c5e88d67c5
22 changes: 22 additions & 0 deletions library/core/src/ops/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,28 @@ impl<T> Bound<T> {
}
}

impl<T: Copy> Bound<&T> {
/// Map a `Bound<&T>` to a `Bound<T>` by copying 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().copied(), Included(1));
/// ```
#[unstable(feature = "bound_copied", issue = "145966")]
pub fn copied(self) -> Bound<T> {
match self {
Bound::Unbounded => Bound::Unbounded,
Bound::Included(x) => Bound::Included(*x),
Bound::Excluded(x) => Bound::Excluded(*x),
}
}
}

impl<T: Clone> Bound<&T> {
/// Map a `Bound<&T>` to a `Bound<T>` by cloning the contents of the bound.
///
Expand Down