tkaitchuck / constrandom

Macro to generate random constants in Rust https://xkcd.com/221/
Apache License 2.0
73 stars 14 forks source link

Use once_cell instead of lazy_static #24

Closed notgull closed 1 year ago

notgull commented 2 years ago

lazy_static is host to a number of bad design patterns. Namely, any other crate in the dependency graph can force lazy_static to fall back on a spinlock-oriented approach through feature unification. In addition, it uses an opaque macro, static mut, and overall takes longer to compile than once_cell. The Rust ecosystem as a whole is migrating to once_cell to avoid these design flaws.

As this crate is depended on by ahash which, in turn, is depended on by many other crates in the Rust ecosystem, it would be beneficial if it no longer depended on lazy_static. In fact, for one of my projects, it is the only time lazy_static appears in the dependency graph. This crate replaces the one time that lazy_static is used, storing and caching the RNG seed, with a once_cell::sync::Lazy.