Re:Rust – How do I create a global, mutable singleton? (2015)
by dgellow on Wednesday July 22, 2020 @12:10PM
(#23918516)
That's not exactly what you mean, but you could do this in Go by using the `init()` function. From there you assign a package level variable to either an object that only exposes public getters, or one that is only exposed/manipulated by public functions.
myVar is constant (though not guaranteed at the type level).
GetMyType() is the only way to access myVar and return a copy, not a reference.