patterns icon indicating copy to clipboard operation
patterns copied to clipboard

idioms dtor-finally should use "defer" library instead

Open bigdogs opened this issue 3 years ago • 2 comments

The sample code in idioms dtor-finally cannot capture outside variable, which means it's useless in most cases

bigdogs avatar Nov 06 '20 13:11 bigdogs

Sorry, I don't understand, can you provide an example or something like that, please? :)

MarcoIeni avatar Dec 24 '20 09:12 MarcoIeni

@bigdogs the struct in the sample code is a unit struct. You could have fields in there too. In the worst case, you can just store a Boxed closure and execute it in the drop impl.

Kushagra-0801 avatar Dec 24 '20 09:12 Kushagra-0801