Skip to content

Commit eb72dc5

Browse files
committed
Add as_ref and as_mut methods for Bound
Add as_ref and as_mut method for std::ops::range::Bound, patterned off of the methods of the same name on Option.
1 parent 76aca66 commit eb72dc5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

library/core/src/ops/range.rs

+23
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,29 @@ pub enum Bound<T> {
678678
Unbounded,
679679
}
680680

681+
#[unstable(feature = "bound_as_ref", issue = "80996")]
682+
impl<T> Bound<T> {
683+
/// Converts from `&Bound<T>` to `Bound<&T>`.
684+
#[inline]
685+
pub fn as_ref(&self) -> Bound<&T> {
686+
match *self {
687+
Included(ref x) => Included(x),
688+
Excluded(ref x) => Excluded(x),
689+
Unbounded => Unbounded,
690+
}
691+
}
692+
693+
/// Converts from `&mut Bound<T>` to `Bound<&T>`.
694+
#[inline]
695+
pub fn as_mut(&mut self) -> Bound<&mut T> {
696+
match *self {
697+
Included(ref mut x) => Included(x),
698+
Excluded(ref mut x) => Excluded(x),
699+
Unbounded => Unbounded,
700+
}
701+
}
702+
}
703+
681704
impl<T: Clone> Bound<&T> {
682705
/// Map a `Bound<&T>` to a `Bound<T>` by cloning the contents of the bound.
683706
///

0 commit comments

Comments
 (0)