Skip to content

Tracking issue: Provide Entry-like API for Option #39288

Closed
@shahn

Description

@shahn
Contributor

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.

Activity

Thinkofname

Thinkofname commented on Jan 25, 2017

@Thinkofname

Isn't this just as_ref/mut().unwrap_or(val) and as_ref/mut().unwrap_or_else(|| val) ?

Edit: These don't modify the original Option which I guess it what you wanted

shahn

shahn commented on Jan 25, 2017

@shahn
ContributorAuthor

indeed

added
B-unstableBlocker: Implemented in the nightly compiler and unstable.
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Feb 4, 2017
added a commit that references this issue on Feb 4, 2017
tbu-

tbu- commented on Feb 6, 2017

@tbu-
Contributor

See also #25149 and #29203. Also, this seems fixed by #39289.

shahn

shahn commented on Feb 6, 2017

@shahn
ContributorAuthor

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-

tbu- commented on Feb 6, 2017

@tbu-
Contributor

Ah, right. Maybe you could put "Tracking issue" in the title.

changed the title [-]Provide Entry-like API for Option[/-] [+]Tracking issue: Provide Entry-like API for Option[/+] on Feb 6, 2017

25 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@alexcrichton@shahn@dhardy@brson

        Issue actions

          Tracking issue: Provide Entry-like API for Option · Issue #39288 · rust-lang/rust