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 upMap entry API: add Entry::or_insert_with_result() #33126
Conversation
rust-highfive
assigned
aturon
Apr 21, 2016
This comment has been minimized.
This comment has been minimized.
|
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
birkenfeld
force-pushed the
birkenfeld:entry_or_insert_with_result
branch
from
c566516
to
0058269
Apr 21, 2016
This comment has been minimized.
This comment has been minimized.
|
Hm, another question: since we're introducing a new type of closure here anyway, should it receive a borrow of the key? (Thinking about cases like @sgrif's https://gist.github.com/sgrif/68cbba9a87084da3a2e8c42a12e7d6cf here.) |
alexcrichton
added
the
T-libs
label
Apr 21, 2016
This comment has been minimized.
This comment has been minimized.
|
I do think these kinds of additions can be useful, but we don't currently have a great convention for them, and of course in the long run it would be sad if every closure-taking function ends up having a We'll discuss this in the next libs team meeting. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Just to chime in since some code from Diesel got referenced in the use case. This is what the code would look like with/without this feature (assuming the closure did in fact take the key as an argument). https://gist.github.com/sgrif/95bdbd302124010a0e4dbc39862313f2 I agree that we don't want every closure-taking function to have a special case for This seems like a good addition, but I don't think it makes sense to change it to take the key, for consistency with
Also my vote for a name would be |
aturon
added
the
I-nominated
label
May 6, 2016
This comment has been minimized.
This comment has been minimized.
|
We didn't quite get to this at this week's libs meeting, but should next week. |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this PR at triage the other day and the conclusion was that we probably don't want to merge this at this time. Handling this in the "most clean" fashion (e.g. with the current Thanks for the PR though @birkenfeld! |
birkenfeld commentedApr 21, 2016
Takes a default function that returns a Result, and bails out
on Err cases. Use case: caches where producing the value
to cache can fail.
To clarify: