Closed CodesInChaos closed 2 years ago
I feel it's best to leave such a feature to a separate helper crate -- the goal of once_cell isn't to provide the most concise API, but to encapsulate unsafety as a reusable primitive.
Closing as out-of-scope!
Often I want to lazily initialize some global state. I feel that
OnceCell
/Lazy
have an unnecessarily complex API for that. I'd like to add a simpleonce!
macro for this use-case:which would be used like:
The requirement to include a type in the macro invocation is unfortunate, but can be made optional once rust supports type inference for statics in a function block.
One thing I particularly like about this macro is that it doesn't directly expose a once_cell based type to the user. This would allow
std
to include such a macro without committing the the full API surfaceonce_cell
would bring with it.