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

Type Parameter for Once #56664

Closed
Ericson2314 opened this issue Dec 10, 2018 · 1 comment
Closed

Type Parameter for Once #56664

Ericson2314 opened this issue Dec 10, 2018 · 1 comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Ericson2314
Copy link
Contributor

Ericson2314 commented Dec 10, 2018

When I made a spin lock version of Once for spin, I added a type parameter so this could act more like a promise of sorts. The is used in, e.g. lazy-static, store the result of the initialization function. It would be nice if Once became Once<T = ()> and offered the same expanded API.

One can always hand roll this with Cell, as lazy-static does when not using spin, but the composition of the Once and interior mutability is unsafe and thus requires extra care. This is exactly analogous to locks without the "slot", as POSIX threads defines the interface, also being unsafe/unergonomic.

Relatedly, there have long been murmers of moving lazy_static itself into std. I'm personally on the fence about that, but if we do so I see no reason why not to generalize Once as this issue proposes. There is also rust-lang-nursery/lazy-static.rs#111 advocating less macro magic by having the Lazy<T> type be exposed. Well, that Lazy<T> is basically Once<T>.

@jonas-schievink jonas-schievink added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Jan 26, 2019
@Mark-Simulacrum
Copy link
Member

I'm going to close this out in favor of moving once_cell/lazy_static into std. I suspect that we'll be doing that fairly soon, and I suspect that adding a type parameter to std::sync::Once is considerably more error prone (it would complicate the type quite a bit, at least).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants