You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ericson2314 opened this issue
Dec 10, 2018
· 1 comment
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
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>.
The text was updated successfully, but these errors were encountered:
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).
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
When I made a spin lock version of
Once
forspin
, 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 ifOnce
becameOnce<T = ()>
and offered the same expanded API.One can always hand roll this with
Cell
, aslazy-static
does when not usingspin
, but the composition of theOnce
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 intostd
. I'm personally on the fence about that, but if we do so I see no reason why not to generalizeOnce
as this issue proposes. There is also rust-lang-nursery/lazy-static.rs#111 advocating less macro magic by having theLazy<T>
type be exposed. Well, thatLazy<T>
is basicallyOnce<T>
.The text was updated successfully, but these errors were encountered: