this post was submitted on 25 Jun 2023
7 points (100.0% liked)

Rust Programming

7734 readers
1 users here now

founded 5 years ago
MODERATORS
 

I want to create a global hash map that maps strings to vectors of colors. This data needs to be queried by multiple functions and should just be hard coded into the program. That doesn't seem possible.

Now, how is the right (tm) way to do something like that in Rust? What if you need just a bunch of data structures from the beginning of the program until its end where some of the data needs to allocated?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 4 points 1 year ago (3 children)
[–] [email protected] 3 points 1 year ago (2 children)

I heard about this, but I wasn't sure it was the right way. Or if Rust developers just straight up avoid situations like this.

[–] [email protected] 5 points 1 year ago

lazy_static was the standard way as far as I'm concerned until this month. OnceCell or OnceLock should fill this role now.

load more comments (1 replies)
load more comments (1 replies)