Skip to content
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

sync: Implement From<T> for OnceCell<T> #3877

Merged
merged 2 commits into from Jun 22, 2021
Merged

Conversation

sb64
Copy link
Contributor

@sb64 sb64 commented Jun 20, 2021

Motivation

std::lazy::OnceCell implements From<T> for OnceCell<T>, but tokio::sync::OnceCell does not. Generally, tokio tries to match std's API as closely as possible, so this could be considered an API hole.

Solution

This PR adds that implementation. While this is a niche case, it also allows tokio::OnceCell to be constructed from a T. As it is right now, one can construct an uninitialized OnceCell with new and const_new, or one that may or may not be initialized using new_with, but it is not possible to construct one directly from a T (although this could be done with new_with(Some(T))).

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels Jun 21, 2021
@sb64 sb64 changed the title sync: Implement From for OnceCell sync: Implement From<T> for OnceCell<T> Jun 21, 2021
@Darksonn Darksonn merged commit 8456264 into tokio-rs:master Jun 22, 2021
@sb64 sb64 deleted the from-oncecell branch June 22, 2021 22:31
@Darksonn Darksonn mentioned this pull request Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants