I'm attempting to define a static Vec
with a struct of my own design for global use in my program (and yes, it does need to be mutable), but I get one of two errors. When given a constructor, the compiler complains and doesn't compile:
static mut stamps: Vec<StampedData> = Vec::new();
error: mutable statics are not allowed to have destructors [E0397]
static mut stamps: Vec<StampedData> = Vec::new();
^~~~~~~~~~
error: statics are not allowed to have destructors [E0493]
static mut stamps: Vec<StampedData> = Vec::new();
^~~~~~~~~~
error: function calls in statics are limited to struct and enum constructors [E0015]
static mut stamps: Vec<StampedData> = Vec::new();
^~~~~~~~~~
note: a limited form of compile-time function evaluation is available on a nightly compiler via `const fn`
static mut stamps: Vec<StampedData> = Vec::new();
^~~~~~~~~~
and when I omit the constructor as I would in, say, Java, I get another complaint:
static mut stamps: Vec<StampedData>;
error: expected one of `!`, `+`, `::`, or `=`, found `;`
static mut stamps: Vec<StampedData>;
^
I understand from these errors that I can't declare globally, then initialize later, nor can I initialize a static, mutable vector. Would the best course of action be to make the variable in main()
and pass a pointer to the functions that need it?