Currently, I am working on a project where I use const (As in const x: i32 = 0;), where the value has to be computed. The reason I'm using const is because it needs to be in the global scope, and I do not want to use static, as that would force me to use unsafe way too many times (So why would I use Rust at that point?).
I am using
const x: i32 = loop {
break y + z;
};
for this purpose. I know this is very unclear, and the compiler probably has no idea how to optimize this garbage code.
Is there a closure-like way to compute a value for a const value, or will I be stuck with loop { break x; }?
My best inference is perhaps they have a complex formula with many intermediate variables that they want scoped just to the initialization of this constant.