Is it possible to use global variables in Rust?
@lebyy▲ 0 net votes
Problem: I know that in general, global-variables are to be avoided. Nevertheless, I think in a practical sense, it is sometimes desirable (in situations where the variable is integral to the program) to use them. In order to learn Rust, I'm currently writing a… Fix (from the top answer): It's possible, but heap allocation is not allowed directly. Heap allocation is performed at runtime. Here are a few examples: static SOME_INT: i32 = 5; static SOME_STR: &'static str = "A static string"; static SOME_STRUCT: MyStruct