I wonder does that mean the code says impl $crate::__Deref for $N in which $N is identifier. Shouldn't it be type? I'm not trying to invalidate the code, but I'm trying to prove my understanding of rust that impl should be doing against type, thus what follows for should be $T instead, and not identifier. I've tried on playground with a simple case against global static variable, and rust compiler expects a type. Anyway, lazy_static code is already in pure correct. So I believe I misread the code.
Any answer to clear this up would be very much appreciated.
A type can be denoted by a single identifier. In fact all primitive types (i32, f64, bool) and user-
defined types currently in scope (e.g. struct and enum types) can be referred to using a single identifier.
You seem to be confusing "identifier" with "variable". Different identifiers refer to different kinds of entities. Some refer to variables, some to constants, some to types, others to functions, etc.
Nope. The Deref impl is for the wrapper which performs the lazy initialization. That's the very point of the macro. The result of the deref operation is &$T, but you can't just implement Deref blindly for the type of the static:
first of all, in that case, impls would conflict if you created multiple lazy_static!s with the same type.
In addition, it's not possible to impl Deref for types you don't own due to orphan rules.
Third, Deref might already be implemented for the type of your static, in which it would be a conflicting impl, too.