3 ms·
It's definitely harder in the general case to run into these bugs, but the real trick, in my opinion, is building APIs where it's impossible. The 'escape hatch
by staticassertion 8y ago
It's definitely harder in the general case to run into these bugs, but the real trick, in my opinion, is building APIs where it's impossible.
The 'escape hatch' here is the .by_ref() but you could, if it's critical, write wrappers that don't provide those escape hatches.
If it were critical that the reuse never happened you can make it impossible, which is really cool. But, by default, for most APIs, it's just generally more difficult to mess up.
There are a bunch of articles on session types out there, where you represent each state in a state machine as a separate type, with transition methods that consume the previous state. If the correctness touted in this article sounds appealing, I highly recommend reading about session types.