Apparently I've been playing a game with myself to see how many times I can answer my own questions in the process of figuring how to phrase them correctly enough to be understandable. Regardless, I still haven't found a firm 'does this exist' in my efforts this time, so I thought it might be worth posting to ask.
The thought is that it would be convenient for my purposes to have a struct, say StateVector, that holds some arbitrary number of values or sub structures, that:
- There will only ever be one instance of
StateVectorin existence for the life of the program. - The sole instance of
StateVectoris constructed at runtime, so any reference to it will either be None (if referenced before it is constructed) or a validStateVector. - The instance is mutable.
- The instance is program scope level.
Such that a function definition could reference the StateVector instance without requiring it as a parameter, something like (hand-waving error handling):
impl FakeStruct { fn check(&self) -> bool { return StateVector.method(&self) } } Const and static seemed to be the closest I could dig up in a short amount of time, but const looks to be compile-time determined, and static looks like it has issues with mutability. Or function definitions can't reference things not declared in their parameters, and I've wandered out into imaginary weeds.
2 posts - 2 participants