Type Parameter for Once #56664
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.
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: