-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock #114788
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
Something like this needs an API Change Proposal (ACP) - you do that by creating an issue on the libs team repo here https://github.com/rust-lang/libs-team (ACP is one of the templates). |
What situation are you trying to solve exactly? (You will need to provide a motivating example in the ACP if you file one). Based on your example on the other thread, this works: use std::cell::OnceCell;
use std::slice::Iter;
type RecordBatch = i32;
struct Foo {
batches: OnceCell<Vec<i32>>
}
impl Foo {
pub fn batches(&self) -> Iter<'_, RecordBatch> {
self.batches
.get_or_init(|| vec![])
.iter()
}
} |
@rustbot label +T-libs-api -T-libs |
But the mut version is awkward: pub fn mut_batches(&mut self) -> IterMut<'_, RecordBatch> {
self.batches.get_or_init(|| load_batches(&self.buf));
// SAFETY - init above
unsafe { self.batches.get_mut().unwrap_unchecked() }.iter_mut()
} |
Can you post a more complete version of a use case? If you're trying to repeatedly edit data behind Also for your example (in case it's coming from real code), I would not use |
Ah, I see your use case here https://github.com/tisonkun/kafka-api/blob/d080ab7e4b57c0ab0182e0b254333f400e616cd2/kafka-api/src/record.rs#L108-L116. It seems like you are happy with using // Old
oncecell.get_or_init(|| foobar());
oncecell.get_mut().unwrap()
// New
oncecell.get_mut_or_init(|| foobar()) That makes more sense. If you write an ACP, link it here |
@tgross35 Thanks for your review! It seems an ACP is an issue at https://github.com/rust-lang/libs-team/issues/new/choose. If so, let me try to find some time and write a formal proposal. |
☔ The latest upstream changes (presumably #116742) made this pull request unmergeable. Please resolve the merge conflicts. |
@tisonkun any updates on the ACP? |
These methods are the equivalent of the |
Thanks for your reply! Let me file an ACP in this week :D |
Breifly outline it here - rust-lang/libs-team#294 Looking forward to your comments and what's the next step I should do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please rebase this, and get it to compile?
#114788 (comment) shows the compile error.
OK. Let me schedule it in weeks. |
This comment was marked as resolved.
This comment was marked as resolved.
@programmerjake would you possibly drop an approval or pull maintainers that can make the decision? I've tried to ask on Zulip. |
Please squash this when you get the chance (still looks ok to me) |
sorry, i'm not one of those who can make a decision here, @dtolnay is assigned, if they haven't responded in a month or so you might be able to use some rustbot command to pick a different assignee, though that could also make it take longer since you'd likely be at the back of that new person's queue. |
See also rust-lang#74465 (comment) Signed-off-by: tison <[email protected]>
fd29d3a
to
95e195f
Compare
@tgross35 squashed. @programmerjake Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thank you!
@bors r+ |
impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock See also rust-lang#74465 (comment) I'm trying to understand the process for such proposal. And I'll appreciate it if anyone can guide me the next step for consensus or adding tests.
impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock See also rust-lang#74465 (comment) I'm trying to understand the process for such proposal. And I'll appreciate it if anyone can guide me the next step for consensus or adding tests.
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#114788 (impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock) - rust-lang#122291 (Stabilize `const_caller_location` and `const_location_fields`) - rust-lang#123321 (Bump dependencies) - rust-lang#123339 (optimize tidy check on `src/tools/tidy/src/issues.txt`) - rust-lang#123357 (CI: Redirect stderr to stdout to order GHA logs) - rust-lang#123504 (bootstrap: split cargo-miri test into separate Step) r? `@ghost` `@rustbot` modify labels: rollup
impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock See also rust-lang#74465 (comment) I'm trying to understand the process for such proposal. And I'll appreciate it if anyone can guide me the next step for consensus or adding tests.
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#114788 (impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock) - rust-lang#122291 (Stabilize `const_caller_location` and `const_location_fields`) - rust-lang#123339 (optimize tidy check on `src/tools/tidy/src/issues.txt`) - rust-lang#123357 (CI: Redirect stderr to stdout to order GHA logs) - rust-lang#123504 (bootstrap: split cargo-miri test into separate Step) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#114788 (impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock) - rust-lang#122291 (Stabilize `const_caller_location` and `const_location_fields`) - rust-lang#123357 (CI: Redirect stderr to stdout to order GHA logs) - rust-lang#123504 (bootstrap: split cargo-miri test into separate Step) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#114788 - tisonkun:get_mut_or_init, r=dtolnay impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock See also rust-lang#74465 (comment) I'm trying to understand the process for such proposal. And I'll appreciate it if anyone can guide me the next step for consensus or adding tests.
Thanks for your review and merge @dtolnay! Two questions here:
|
|
See also #74465 (comment)
I'm trying to understand the process for such proposal. And I'll appreciate it if anyone can guide me the next step for consensus or adding tests.