You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking issue: Provide Entry-like API for Option #39288
Often I have code where Option is used to indicate whether a value has been initialized or not. In these instances I often have code that either wants to use the value directly or initialize it and then use the value. So what I'm looking for is similar to as_ref()/as_mut() except they should return &T/&mut T respectively, and take either a value or a closure.
I think I would call the functions get{,_mut}_or_insert{,with}() marrying the get functions (for example in hashmaps) for getting references with the or_insert Entry like functions.
Reacted by Marcell Pardavi, Martin Carton and Jaro Fietz
AIUI, this is not fixed by #39289, because this issue is referenced as the tracking issue for the implementation and should stay open until it's decided whether this is to be stabilized or backed out.
@raphlinusI think that commit is wrong :-) The function in question doesn't show up in the 1.20.0 docs but does in the 1.21.0 docs. Nope, never mind; I just forgot how to search, sigh.
GitHub does say that commit is only in the 1.21.0 tag though...
Activity
Thinkofname commentedon Jan 25, 2017
Isn't this just
as_ref/mut().unwrap_or(val)andas_ref/mut().unwrap_or_else(|| val)?Edit: These don't modify the original
Optionwhich I guess it what you wantedshahn commentedon Jan 25, 2017
indeed
Provide Entry-like API for Option
tbu- commentedon Feb 6, 2017
See also #25149 and #29203. Also, this seems fixed by #39289.
shahn commentedon Feb 6, 2017
AIUI, this is not fixed by #39289, because this issue is referenced as the tracking issue for the implementation and should stay open until it's decided whether this is to be stabilized or backed out.
tbu- commentedon Feb 6, 2017
Ah, right. Maybe you could put "Tracking issue" in the title.
[-]Provide Entry-like API for Option[/-][+]Tracking issue: Provide Entry-like API for Option[/+]oberien commentedon May 22, 2017
As this issue is quite old already (over 3 months), would it be possible to stabilize these two functions soon?
7 remaining items
rfcbot commentedon Jun 16, 2017
The final comment period is now complete.
dhardy commentedon Jun 26, 2017
This isn't
Entry-like. If it was, it would be possible to do the following:SimonSapin commentedon Jun 27, 2017
@dhardy That particular example can be written as:
std: Stabilize `option_entry` feature
raphlinus commentedon Nov 1, 2017
To save time for people researching this, the feature landed in stable at Rust 1.20 (source: 64c1b23).
shepmaster commentedon Nov 1, 2017
@raphlinus
I think that commit is wrong :-) The function in question doesn't show up in the 1.20.0 docs but does in the 1.21.0 docs.Nope, never mind; I just forgot how to search, sigh.GitHub does say that commit is only in the 1.21.0 tag though...
shepmaster commentedon Nov 1, 2017
Ah, the 1.20.0 commit was a backport, thus why it's a different tag.