Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy static with custom attribute #126

Closed
real-felix opened this issue Oct 5, 2018 · 1 comment
Closed

Lazy static with custom attribute #126

real-felix opened this issue Oct 5, 2018 · 1 comment

Comments

@real-felix
Copy link

Is it planed to have a custom attribute for lazy static? For example:

#[lazy] static ref HASHMAP: HashMap<u32, &'static str> = {
    let mut m = HashMap::new();
    m.insert(0, "foo");
    m.insert(1, "bar");
    m.insert(2, "baz");
    m
};
@KodrAus
Copy link
Contributor

KodrAus commented Oct 15, 2018

Hi @Boiethios, since the lazy_static macro lies about its type in the declaration I think we could create more confusion by not having it explicitly wrapped in a macro, where you can expect to be outside the realms of standard Rust syntax.

As another alternative, I personally like the API from #111 where the macro moves just to the body of the static declaration:

static GLOBAL_DATA: Lazy<Mutex<HashMap<i32, String>>> = sync_lazy! {
    let mut m = HashMap::new();
    m.insert(13, "Spica".to_string());
    m.insert(74, "Hoyten".to_string());
    Mutex::new(m)
};

Moving away from a wrapper macro like your suggestion, or the one from #111, does have the benefit of being understandable by tooling as just a normal static declaration rather than a block-box macro.

@real-felix real-felix closed this as not planned Won't fix, can't repro, duplicate, stale Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants