Skip to content

Commit

Permalink
Rollup merge of #99736 - lopopolo:lopopolo/gh-80996-partial-stabiliza…
Browse files Browse the repository at this point in the history
…tion-bounds-as-ref, r=dtolnay

Partially stabilize `bound_as_ref` by stabilizing `Bound::as_ref`

Stabilizing `Bound::as_ref` will simplify the implementation for `RangeBounds<usize>` for custom range types:

```rust
impl RangeBounds<usize> for Region {
    fn start_bound(&self) -> Bound<&usize> {
        // TODO: Use `self.start.as_ref()` when upstream `std` stabilizes:
        // rust-lang/rust#80996
        match self.start {
            Bound::Included(ref bound) => Bound::Included(bound),
            Bound::Excluded(ref bound) => Bound::Excluded(bound),
            Bound::Unbounded => Bound::Unbounded,
        }
    }

    fn end_bound(&self) -> Bound<&usize> {
        // TODO: Use `self.end.as_ref()` when upstream `std` stabilizes:
        // rust-lang/rust#80996
        match self.end {
            Bound::Included(ref bound) => Bound::Included(bound),
            Bound::Excluded(ref bound) => Bound::Excluded(bound),
            Bound::Unbounded => Bound::Unbounded,
        }
    }
}
```

See:

- #80996
- rust-lang/rust#80996 (comment)

cc `@yaahc` who suggested partial stabilization.
  • Loading branch information
Dylan-DPC authored Sep 3, 2022
2 parents ea6e6dc + b495a74 commit 81dedc6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/ops/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ pub enum Bound<T> {
impl<T> Bound<T> {
/// Converts from `&Bound<T>` to `Bound<&T>`.
#[inline]
#[unstable(feature = "bound_as_ref", issue = "80996")]
#[stable(feature = "bound_as_ref_shared", since = "CURRENT_RUSTC_VERSION")]
pub fn as_ref(&self) -> Bound<&T> {
match *self {
Included(ref x) => Included(x),
Expand Down

0 comments on commit 81dedc6

Please sign in to comment.