Skip to content

Commit

Permalink
Rollup merge of rust-lang#99736 - lopopolo:lopopolo/rust-langgh-80996-…
Browse files Browse the repository at this point in the history
…partial-stabilization-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#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#80996
        match self.end {
            Bound::Included(ref bound) => Bound::Included(bound),
            Bound::Excluded(ref bound) => Bound::Excluded(bound),
            Bound::Unbounded => Bound::Unbounded,
        }
    }
}
```

See:

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

cc `@yaahc` who suggested partial stabilization.
  • Loading branch information
Dylan-DPC authored Sep 3, 2022
2 parents 0209485 + 773df67 commit 2ed716a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion library/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 2ed716a

Please sign in to comment.