rust-lang-nursery / lazy-static.rs

A small macro for defining lazy evaluated static variables in Rust.
Apache License 2.0
1.9k stars 108 forks source link

Use underlying type? #188

Closed vedantroy closed 3 years ago

vedantroy commented 3 years ago

Is it possible to use the underlying type? It seems like this macro generates custom types, which makes it hard to pass the global variables into, for example, functions.

Kimundi commented 3 years ago

The underlying type is accessible via Deref impl. If you pass this to generic code, you might have to be explicit in dereferencing:


lazy_static! {
    static ref FOO: T = T::new();
}

let x: &T = &*FOO;