Yeah, it’d be interesting to see the Rust code contrasted with correct C versions. How does the C code deal with a monitor being unplugged? I wonder if it could be shuffled around to amount to an early return with an Unplugged error.
In C, you're supposed to listen for a "destroy" event on the output and then in the handler you would delete all your references to the object. I would be interested to know if any language has a way to statically analyze this, instead of using a monad.