Description
I've been thinking about wether it would make sense to change the macro name and syntax. The main argument here is consistency with std
macros like https://doc.rust-lang.org/std/macro.thread_local.html.
Compare:
thread_local! {
static FOO: u32 = 1;
}
vs
lazy_static! {
static ref FOO: u32 = 1;
}
There are two notable differences:
- The name contains the redundant
_static
. - The
ref
keyword.
The ref
had been chosen to indicate the need for a deref to get to the value, but that's not quite the same as a reference, so thats not really accurate either, and getting rid of it would mean less complexity as you could learn both macros as "normal static syntax inside a special macro invocation".
The lazy_static!
name as opposed to, eg, lazy!
had just been a carry over from before this was even a library, and its main benefit is that with the current macros 1.0, we effectively have a global macro namespace, so a less generic name helps avoiding namespace conflicts.
With macros 2.0 though, a version of this crate would likely offer a proper importable macro, which means you might end up defining lazy statics like this:
extern crate lazy_static;
lazy_static::lazy_static! {
// ...
}
extern crate lazy_static;
use lazy_static::lazy_static; // possible namespace conflict?
lazy_static! {
// ...
}