Closed freiguy1 closed 9 years ago
So, you mean use a Config as a global variable?
Yes, exactly
This has been asked before on StackOverflow - see http://stackoverflow.com/questions/19605132/is-it-possible-to-use-global-variables-in-rust for further info, although the post is slightly outdated now: the most voted answer mentions the deprecated ~
pointer syntax, so take it with a grain of salt, but it looks to me like you want to do something similar to the db
variable example in that answer.
Do keep in mind that it is generally bad practice to do so (and I believe that's why Rust makes it non-trivial).
I also checked the Rust documentation; it briefly mentions global variables here.
Maybe you could design your program so as to keep references to the Config
instance where necessary?
Thanks for the information. I'll try to design the program without global variables.
This may be a rust language question, rather than a question for you, but say I want to read in a config file and parse it once at the beginning of my program. Then at any time, I can get values from the pre-parsed Config by accessing it as a static struct. I'd rather not pass the config around everytime I create a new struct that might have use of it.
Thanks!