12

lazy_static is a very popular crate. Years ago it had no better alternatives for certain tasks. But today, are there still any reasons to choose lazy_static over the newer once_cell or the upcoming LazyLock?

at54321
  • 8,726
  • 26
  • 46

2 Answers2

5

If you'd like to support #![no_std] platforms, you may still prefer to use lazy_static. As per the once_cell documentation :

Unlike once_cell, lazy_static supports spinlock-based implementation of blocking which works with #![no_std].

antonok
  • 516
  • 6
  • 9
4

once_cell and LazyLock have a minimum support version of the compiler. For earlier versions of it you would probably want to stick to lazy_static which has served it purpose pretty well when less features were available.

Netwave
  • 40,134
  • 6
  • 50
  • 93