I have a symbol table that I want to be static because it is accessed in a lot of circumstances where I don't have a good way to pass the value in. It is a struct and a table that looks like:
struct Symbol {
string: &'static str,
other_values: ...,
}
const NO_SYMBOL = Symbol{ string: "", other...};
static mut symbol_table : [Symbol;100] = [NO_SYMBOL;100];
How do I update the string field? It has to be static, because it's in a static array, but I want to generate values (among other things, by reading from a file), so how can I make a String static so I can store it in an element of the array?
&'static stris a string either baked in the binary or leaked. Are you sure you really need this and notString/Box<str>?Cow<'static, str>would allos mixing static strings created at compile time and dynamic strings allocated at runtime.lazy_static!with proper synchronisation would probably be a better idea than a bare static mut`, those are gnarly.