-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 Option::deref, Result::deref, Result::deref_ok, and Result::deref_err (feature: inner_deref) #50264
Comments
closed prematurely |
inner_deref PR tracking issue: rust-lang#50264
Implement inner deref for Option and Result tracking issue: #50264
I just found this useful! Thanks @Centril for pointing me here. :) However, the name is a bit odd: It goes from |
Ah, naming... :) |
Oh, the method name collides I think |
What about the name |
It's less about expressiveness than discoverability I feel. I know the
as_ref + &** trick but it's hard to land on as a learner.
…On Sun, Jan 13, 2019, 18:57 HeroicKatora ***@***.*** wrote:
What about the name deref_inner for the case of Option and both arguments
of Result; although the more though I put into it the more as_deref seems
correct? Compared to other ref-utils this is missing the mut variants
such as deref_ok_mut. I have mixed feelings about the api as a whole
though, is there enough expressiveness advantage over a plain result.as_ref().map(|t|
&**t)?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#50264 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3nxzC19t6xTAx6Rj5F44SzM-XmPliks5vC8fbgaJpZM4TpOU5>
.
|
@RalfJung correctly points out that there's as much Also agree with @HeroicKatora that the |
Hm, I see how this could be troubling at first, even more so with
Another possibility would be to instead give those methods the type of
with usage |
I just started making use of Using I have a reference to an let parent_node: &Inert<Option<Dom<Node>>;
// Without Option::deref:
(**parent_node).as_ref().map(|node| &**node);
// With Option::deref:
parent_node.deref(); To summarise, this method helps a lot if you have a reference to something which derefs to |
Turned into a tracking issue, since |
About the name: As I'm mostly going to use it to replace a method named About the signature: I've yet to encounter a case where I'm fed something like |
This seems great to me. This has been around for a long time; other than discussions around the name, is there any reason we shouldn't stabilize this? |
@joshtriplett 1) the name and 2) the *Mut flavors of these FYI, I've already started work on the *Mut side of things; I expect be able to have the new PR ready by the end of the month, if not before (sorry, my external commitments prevent me from being more precise than that at this point...). In terms of naming, I've been kicking around (no particular order):
Personally, I feel the current Given that, personally I am leaning slightly toward Brevity is important, as is a (reasonably unambiguous) descriptive name. Please weigh in if you have thoughts any of these method names or ideas for others, and I'll try to put the zeitgeist into the upcoming PR. |
On March 15, 2019 11:06:02 PM PDT, Brad Gibson ***@***.***> wrote:
@joshtriplett the name and the *Mut flavors of these
FYI, I've already started work on the *Mut side of things; I expect be
able to have the new PR ready by the end of the month, if not before
(sorry, my external commitments prevent me from being more specific
than that at this point...).
In terms of naming, I've been kicking around (no particular order):
* `as_ref_deref/as_mut_deref` (describes &**, without being too
pedantic (i.e. avoid "as_ref_deref_deref/..."), and
* `as_inner_deref/as_inner_deref_mut` (differentiates from
`deref/deref_mut` and implies what kinds of transformations to expect)
Personally, I feel the current `deref/deref_mut` is a bit misleading,
given how it is (generally) used in the rest of `std` (I understand
there are departures from this convention already, but I do not want to
use that as a license to lower consistency further.)
Personally, I am leaning slightly toward `as_ref_deref/as_mut_deref`
because it is both distinct and descriptive.
Brevity is important, as is a (reasonably unambiguous) descriptive
name. Please weigh in if you have thoughts any of these method names
or ideas on others, and I'll try to put the zeitgeist into the upcoming
PR.
Shorter seems preferable here; `as_deref` seems as long as it should get.
|
Given we have |
On March 20, 2019 4:07:49 PM PDT, Joey ***@***.***> wrote:
Given we have `cloned` for `Clone` and soon `copied` for `Copy`, what
about `derefed`?
Those are for iterators. I'd be all for an iterator operation to deref elements and calling that derefed. However, for Option, I think we should use "deref" or "as_deref".
|
This is a decent set of changes to tuftool. It fully removes the KeySource enum in source.rs and instead uses the KeySource trait from tough. This commit also removes all SSM related code in favor of the tough-ssm crate (which is a copy of this code). It also removes the deref.rs file, as it is no longer need because these features have stabilized in upstream Rust. See: rust-lang/rust#50264 and rust-lang/rust#64708
This is a decent set of changes to tuftool. It fully removes the KeySource enum in source.rs and instead uses the KeySource trait from tough. This commit also removes all SSM related code in favor of the tough-ssm crate (which is a copy of this code). It also removes the deref.rs file, as it is no longer need because these features have stabilized in upstream Rust. See: rust-lang/rust#50264 and rust-lang/rust#64708
This is a decent set of changes to tuftool. It fully removes the KeySource enum in source.rs and instead uses the KeySource trait from tough. This commit also removes all SSM related code in favor of the tough-ssm crate (which is a copy of this code). It also removes the deref.rs file, as it is no longer need because these features have stabilized in upstream Rust. See: rust-lang/rust#50264 and rust-lang/rust#64708
This is a decent set of changes to tuftool. It fully removes the KeySource enum in source.rs and instead uses the KeySource trait from tough. This commit also removes all SSM related code in favor of the tough-ssm crate (which is a copy of this code). It also removes the deref.rs file, as it is no longer need because these features have stabilized in upstream Rust. See: rust-lang/rust#50264 and rust-lang/rust#64708
This is a decent set of changes to tuftool. It fully removes the KeySource enum in source.rs and instead uses the KeySource trait from tough. This commit also removes all SSM related code in favor of the tough-ssm crate (which is a copy of this code). It also removes the deref.rs file, as it is no longer need because these features have stabilized in upstream Rust. See: rust-lang/rust#50264 and rust-lang/rust#64708
This is a decent set of changes to tuftool. It fully removes the KeySource enum in source.rs and instead uses the KeySource trait from tough. This commit also removes all SSM related code in favor of the tough-ssm crate (which is a copy of this code). It also removes the deref.rs file, as it is no longer need because these features have stabilized in upstream Rust. See: rust-lang/rust#50264 and rust-lang/rust#64708
@rust-lang/libs: Judging by https://grep.app/search?q=as_deref%28_mut%29%3F%5C%28%5C%29®exp=true&filter[lang][0]=Rust, the I am interested in stabilizing these corresponding two methods on Result. The first was added in #50267 under the name fn as_deref(&self) -> Result<&T::Target, &E> where T: Deref;
fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E> where T: DerefMut; Additionally I propose removing the remaining two methods tracked by this tracking issue. I expect these to be much less commonly applicable and they can be written instead as fn as_deref_err(&self) -> Result<&T, &E::Target> where E: Deref;
fn as_deref_mut_err(&mut self) -> Result<&mut T, &mut E::Target> where E: DerefMut; |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
How discoverable is that, though? After all, the exact same argument applies to the methods that are being stabilized. Only stabilizing the |
…=dtolnay Improve document for `Result::as_deref(_mut)` methods cc rust-lang#50264
🔔 This is now entering its final comment period, as per the review above. 🔔 |
…=dtolnay Improve document for `Result::as_deref(_mut)` methods cc rust-lang#50264
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
API
Implementation history
Implemented in Implement inner deref for Option and Result #50267 as:
Renamed and extended in
as_deref()
andas_deref_mut()
impls #59628 / Introduceas_deref
to Option #62421:Option
methods stabilized in StabilizeOption::as_deref
andOption::as_deref_mut
#64708:Result
methods pared down and renamed in Rename Result::as_deref_ok to as_deref #67930:The text was updated successfully, but these errors were encountered: