Closed
Description
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.
Metadata
Metadata
Assignees
Labels
Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCRelevant to the library API team, which will review and decide on the PR/issue.In the final comment period and will be merged soon unless new substantive objections are raised.
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
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
Option
which 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[/+]25 remaining items