News for hackers. Stuff that matters.
Re:Rust means never having to close a socket by lambda on Tuesday October 07, 2014 @09:05PM (#8424841)
Right. One case in which I've come across this problem in Python is writing unit tests for code using Twisted (and Trial, Twisted's unit test framework) with @inlineCallbacks, and trying to also use this style of resource management for mocks (or, essentially the same, the @patch decorator to set up the mocks).

If you have something like:

   @patch('some_module.some_object')
   @inlineCallbacks
   def test_my_stuff(self):
       do_stuff()
       yield some_operation()
       do_more_stuff()
       self.assertFalse(True)
Then you run into the problem that @patch has cleaned up all of your mocks by the time the yield returns.

Now, I haven't tried to do anything equivalent in Rust; I'm not sure what the idiomatic equivalent would be. But having more explicit control of lifetime, rather than it always depending specifically on that stack frame, seems like it might help here.

There are no comments on this comment yet.