Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4ac831b

Browse files
authoredJan 14, 2021
Rollup merge of rust-lang#80444 - glittershark:bound-as-ref, r=dtolnay
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. I'm not quite sure what the process is for introducing new feature gates (this is my first contribution) so I've left these ungated, but happy to do whatever is necessary to gate them.
2 parents 35833c2 + eb72dc5 commit 4ac831b

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)
Please sign in to comment.