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: Provide Entry-like API for Option #39288
Comments
shahn
added a commit
to shahn/rust
that referenced
this issue
Jan 25, 2017
This comment has been minimized.
This comment has been minimized.
Thinkofname
commented
Jan 25, 2017
•
|
Isn't this just Edit: These don't modify the original |
This comment has been minimized.
This comment has been minimized.
|
indeed |
frewsxcv
added
the
A-libs
label
Jan 25, 2017
alexcrichton
added
B-unstable
T-libs
labels
Feb 4, 2017
shahn
added a commit
to shahn/rust
that referenced
this issue
Feb 4, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Feb 5, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Feb 5, 2017
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
Ah, right. Maybe you could put "Tracking issue" in the title. |
shahn
changed the title
Provide Entry-like API for Option
Tracking issue: Provide Entry-like API for Option
Feb 6, 2017
steveklabnik
removed
the
A-libs
label
Mar 24, 2017
This comment has been minimized.
This comment has been minimized.
|
As this issue is quite old already (over 3 months), would it be possible to stabilize these two functions soon? |
brson
added
the
I-nominated
label
May 22, 2017
This comment has been minimized.
This comment has been minimized.
|
@rfcbot merge |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
May 23, 2017
•
|
Team member @brson has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, 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. |
This comment has been minimized.
This comment has been minimized.
|
To be clear, the APIs proposed here for stabilization are: impl<T> Option<T> {
fn get_or_insert(&mut self, v: T) -> &mut T;
fn get_or_insert_with<F: FnOnce() -> T>(&mut self, f: F) -> &mut T;
} |
alexcrichton
removed
the
I-nominated
label
Jun 5, 2017
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Jun 6, 2017
|
|
rfcbot
added
the
final-comment-period
label
Jun 6, 2017
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Jun 16, 2017
|
The final comment period is now complete. |
This comment has been minimized.
This comment has been minimized.
|
This isn't
|
This comment has been minimized.
This comment has been minimized.
|
@dhardy That particular example can be written as: match opt_value {
ref mut entry @ None => *entry = Some(x),
Some(ref entry) => assert_eq!(entry, x),
} |
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Jul 20, 2017
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 22, 2017
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Jul 23, 2017
bors
closed this
in
64c1b23
Jul 27, 2017
mattico
added a commit
to mattico/rust
that referenced
this issue
Jul 29, 2017
matthewhammer
pushed a commit
to matthewhammer/rust
that referenced
this issue
Aug 3, 2017
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Aug 12, 2017
This comment has been minimized.
This comment has been minimized.
|
To save time for people researching this, the feature landed in stable at Rust 1.20 (source: 64c1b23). |
This comment has been minimized.
This comment has been minimized.
|
@raphlinus GitHub does say that commit is only in the 1.21.0 tag though... |
This comment has been minimized.
This comment has been minimized.
|
Ah, the 1.20.0 commit was a backport, thus why it's a different tag. |
shahn commentedJan 25, 2017
•
edited
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.