Skip to content

Commit

Permalink
Rollup merge of rust-lang#80444 - glittershark:bound-as-ref, r=dtolnay
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JohnTitor authored Jan 14, 2021
2 parents 97466c6 + eb72dc5 commit 4204450
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions library/core/src/ops/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,29 @@ pub enum Bound<T> {
Unbounded,
}

#[unstable(feature = "bound_as_ref", issue = "80996")]
impl<T> Bound<T> {
/// Converts from `&Bound<T>` to `Bound<&T>`.
#[inline]
pub fn as_ref(&self) -> Bound<&T> {
match *self {
Included(ref x) => Included(x),
Excluded(ref x) => Excluded(x),
Unbounded => Unbounded,
}
}

/// Converts from `&mut Bound<T>` to `Bound<&T>`.
#[inline]
pub fn as_mut(&mut self) -> Bound<&mut T> {
match *self {
Included(ref mut x) => Included(x),
Excluded(ref mut x) => Excluded(x),
Unbounded => Unbounded,
}
}
}

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

0 comments on commit 4204450

Please sign in to comment.