HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
rust-lang-nursery
lazy-static.rs
Rust2014–2021
rust-lang-nursery / lazy-static.rs · Archived

lazy-static.rs

A small macro for defining lazy evaluated static variables in Rust.

6Distinct people
6Mentions
1Explicit recommenders
2KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

A small macro for defining lazy evaluated static variables in Rust.

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

Much like Go! i'm not a big fan of languages whose includes are managed as such: [dependencies.lazy_static] git = "https://github.com/Kimundi/lazy-static.rs" Does Rust, like…

killertypo used a recommendation phrase. One indexed comment matches. This is a phrase match, not a verdict.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 5:04:57 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year6 dated mentions

Observed mentions: 2014-10-29 22:00:38 UTC to 2021-04-17 15:12:33 UTC.

0122014-01-01 00:00:00 UTC to 2015-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments20142015-01-01 00:00:00 UTC to 2016-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2016-01-01 00:00:00 UTC to 2017-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments20172018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2021

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20142014-01-01 00:00:00 UTC2015-01-01 00:00:00 UTC202
20152015-01-01 00:00:00 UTC2016-01-01 00:00:00 UTC000
20162016-01-01 00:00:00 UTC2017-01-01 00:00:00 UTC101
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC101
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC000
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC101
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC000
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC101

What Hacker News says

6 sources
As someone who also completed Advent of Code in Rust this year this was very interesting. I agree it is a great way to learn more about a new language. Thanks for sharing! It seems like we ran into a lot of the same pain points like parsing, lack of a min-heap, etc. Regarding HashMap initialization the best way I'm aware of to do what you are looking for is with lazy_static[0]. Maybe not very clean or idiomatic though. For sorting I found the best solution to that problem was using sort_by_key with a tuple like (a.year, a.month, a.day, a.hour, a.minute). [0]: https://github.com/rust-lang-nursery/lazy-static.rs#example
In Learning Rust via Advent of Code
I'm an embedded Rust developer, and was a little confused by this paper until I noticed it was written in 2015. There are now solutions to a number of the problems they pose both at the language level and the library level: Here's one in particular: In principal, this would allow us to statically allocate a buffer sized for each particular closure. Unfortunately, there is no size_of keyword in Rust, and static initialization cannot invoke functions— in this case the function size_of<T>() -> usize provided by the Rust core library. This can be solved by using the lazy_static crate: https://github.com/rust-lang-nursery/lazy-static.rs From the description in the README: Using this macro, it is possible to have statics that require code to be executed at runtime in order to be initialized. Hey look,
Read the rest
it's exactly what they need! It's also "no_std" compatible and can work just fine in a kernel-like context. Take this paper with a grain of salt: it's a bit dated at this point, and there are solutions for a number of the problems posed.
In Ownership is Theft: Experiences Building an Embedded OS in Rust (2015) [pdf]
Rust is very-very explicit. Whereas every event-driven framework is (usually) a full-throttle magical land of monkey patching or wrapping everything, plus the not so well advertised, but very forbidden dark marshes full of nasty blocking I/O goblins, and usually this means there's no proper API to use the async parts without the magic of the event loop. In Rust you'd have to either make an few (unsafe) global ( https://github.com/rust-lang-nursery/lazy-static.rs ) structures to keep track of the event-driven state, or pass them into every callback, or make every callback somehow derive (or a derived from) a common structure that does this bookkeeping. So far the language doesn't have syntactic sugar for this, but I think it'll be there in a few years. The compiler is up to the task (as you can already see a few 3rd party macro-driven solu
Read the rest
tions for similar "magic" things - such as serde's custom macros). But since every event-driven thing can be implemented as a queue and a consumer thread pool (as it's implemented under the event-driven hood), I don't think Rust is a non-starter for even-driven solutions. Though I'm inclined to agree on the extra care needed to satisfy the type system to get easy callbacks is annoying.
In Ruma, a Matrix homeserver written in Rust
I'm not a Go expert at all, but I believe Cargo (the dependency management tool) far surpasses Go in this respect. One of the main design goals for Cargo is reproducable builds. E.g. the first time anything is build Cargo will create a Cargo.lock[0] file that fixes the dependency at the exact commit that the build used, so one can come back in a year and rerun to get the same result (assuming upstream hasn't edited their history). Upgrading/changing a dep then requires explicitly calling `cargo upgrade`. One can also manually specify versions and exact commits[1] in the Cargo.toml (the file written to specify those deps), e.g. [dependencies.lazy_static] git = "https://github.com/Kimundi/lazy-static.rs" version = "1.1" [0]: e.g. https://github.com/servo/servo/blob/master/Cargo.lock (machine generated/consumed) [1]: http://doc.crates
Read the rest
In A taste of Rust for C/C++ programmers
killertypo·Oct 29, 2014Recommendation phrase
Much like Go! i'm not a big fan of languages whose includes are managed as such: [dependencies.lazy_static] git = "https://github.com/Kimundi/lazy-static.rs" Does Rust, like Go, have tools for freezing dependencies? So when the git project changes, you're not left wondering why a project has sudden bugs not seen before? I love the idea of how easy these can be included in a project, but I dislike leaning on a public repository that may change at a moments notice. For as much as I hate Maven for some reasons, I do appreciate the ecosystem and the ease at which I can...say, ask for a specific version of a specific artifact - ensuring my application will always build.
In A taste of Rust for C/C++ programmers

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.