Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for Option::deref, Result::deref, Result::deref_ok, and Result::deref_err #50264
Comments
U007D
closed this
in
humanenginuity/rust#1
Apr 27, 2018
This comment has been minimized.
This comment has been minimized.
|
closed prematurely |
U007D
reopened this
Apr 27, 2018
Mark-Simulacrum
added
T-libs
C-feature-request
labels
May 27, 2018
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this issue
Jul 30, 2018
bors
added a commit
that referenced
this issue
Jul 31, 2018
bors
added a commit
that referenced
this issue
Jul 31, 2018
This comment has been minimized.
This comment has been minimized.
|
I just found this useful! Thanks @Centril for pointing me here. :) However, the name is a bit odd: It goes from |
This comment has been minimized.
This comment has been minimized.
|
Ah, naming... :) |
DJMcNab
referenced this issue
Dec 18, 2018
Merged
By default, log only to stderr, and not to disk. #284
This comment has been minimized.
This comment has been minimized.
uHOOCCOOHu
commented
Dec 21, 2018
|
Oh, the method name collides I think |
This comment has been minimized.
This comment has been minimized.
HeroicKatora
commented
Jan 13, 2019
|
What about the name |
This comment has been minimized.
This comment has been minimized.
|
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>
.
|
This comment has been minimized.
This comment has been minimized.
|
@RalfJung correctly points out that there's as much Also agree with @HeroicKatora that the |
This comment has been minimized.
This comment has been minimized.
HeroicKatora
commented
Jan 14, 2019
•
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 |
SimonSapin
changed the title
&Option<String> -> Option<&str>
Tracking issue for Option::deref, Result::deref, Result::deref_ok, and Result::deref_err
Mar 10, 2019
SimonSapin
added
B-unstable
C-tracking-issue
and removed
C-feature-request
labels
Mar 10, 2019
This comment has been minimized.
This comment has been minimized.
|
Turned into a tracking issue, since |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
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.
|
This comment has been minimized.
This comment has been minimized.
OddCoincidence
commented
Mar 20, 2019
|
Given we have |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
@joshtriplett Option has a |
This comment has been minimized.
This comment has been minimized.
OddCoincidence
commented
Mar 21, 2019
|
Also |
This comment has been minimized.
This comment has been minimized.
|
I would expect |
This comment has been minimized.
This comment has been minimized.
OddCoincidence
commented
Mar 21, 2019
|
Oh, I didn't realize that - I assumed it was |
This comment has been minimized.
This comment has been minimized.
|
It has already been discussed earlier. |
This comment has been minimized.
This comment has been minimized.
HeroicKatora
commented
Mar 21, 2019
•
|
@nox @OddCoincidence Yes, I had thrown that into the room for discussion. Ultimately, the gut feeling of myself, and apparently others, is that this makes it much less useful. There's of course the interesting insight that the intermediate Simply standing in for In addition, I think that
feels wrong/would have me ponder my life choices and could be seen as an indicator that the name should not be strictly oriented around the trait it borrows from. |
This comment has been minimized.
This comment has been minimized.
|
Indeed, naming is hard(TM). ;) |
U007D
added a commit
to U007D/rust
that referenced
this issue
Apr 2, 2019
U007D
added a commit
to U007D/rust
that referenced
this issue
Apr 2, 2019
This comment has been minimized.
This comment has been minimized.
|
PR submitted with name change and *_mut impls + sanity-check tests. |
U007D commentedApr 27, 2018
•
edited by SimonSapin
#50267 implemented these APIs:
Original feature request:
&Option -> Option<&str> and related functionality for Result (&Result<T, E> -> Result<&T, &E>) seem to be missing in std.
Conversations with @lucasem @QuietMisdreavus, @durka and UndeadLeech on irc led us to create this issue: namely to have a single-shot Option/Result function to map through Deref.