-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for bound_as_ref #80996
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This has been unstable since Jan 14 and seems relatively uncontroversial, modulo that issue, so I'd love to get the stabilization process kicked off. @dtolnay you reviewed the original PR, any qualms with that? |
But does anybody so far have a real world use case for |
it would seem weird to have as_ref and not as_mut, wouldn't it? especially since Option has both. I feel like that violates principle of least surprise. |
Okay but |
I guess my point is that if |
Team member @dtolnay has asked teams: T-libs-api, for consensus on:
|
Team member @dtolnay has asked teams: T-libs-api, for consensus on:
|
That poll wording seems a little... leading, doesn't it? I think calling |
@glittershark Could you perhaps elaborate a bit more? Is it possible to show a short code sample? I think that if But if it affords a little extra flexibility or convenience in some cases, then I think i'd be inclined to add it, mostly because my bar for adding |
Then you'd still have to match on the |
yeah, that's fair - it's not often you'd want |
I did have a bit of a lightbulb about this since last time I was engaged in the discussion, which was that perhaps (tell me if I'm wrong) @dtolnay's hesitation about |
I'm also using |
I'm implementing my own Range type with impl RangeBounds<usize> for Region {
fn start_bound(&self) -> Bound<&usize> {
// TODO: Use `self.start.as_ref()` when upstream `std` stabilizes:
// https://github.com/rust-lang/rust/issues/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:
// https://github.com/rust-lang/rust/issues/80996
match self.end {
Bound::Included(ref bound) => Bound::Included(bound),
Bound::Excluded(ref bound) => Bound::Excluded(bound),
Bound::Unbounded => Bound::Unbounded,
}
}
} |
Collapse a couple verbose `match` expressions to use the `Bound::cloned` API which was stabilized in Rust 1.55.0. Add a note and track the stabilization of rust-lang/rust#80996 to replace more `match` expressions with `Bound::as_ref`.
Would it be possible to split this tracking issue into two features, propose |
Although consistency is a significant design consideration in many situations, I don't believe it is sufficient justification to add APIs on its own. We've updated our API proposal process since this API was added1, and the template that goes along with it includes a mandatory section for motivating examples. This should hopefully show how important real-world motivating use cases are to us. Otherwise, we'll have a ton of pretty methods that nobody uses and that serve only as clutter in the documentation. I advise sticking with David's original recommendation and stabilizing
I'd just skip straight to a partial stabilization2 personally. Footnotes |
@yaahc I put up a partial stabilization PR here: |
…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.
…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.
Feature gate:
#![feature(bound_as_ref)]
This is a tracking issue for providing
as_ref
andas_mut
on bound. These methods mirror similar methods on theOption
type.Public API
Steps / History
Unresolved Questions
The text was updated successfully, but these errors were encountered: