nim-lang / RFCs

A repository for your Nim proposals.
135 stars 26 forks source link

Destructors for streams #316

Open planetis-m opened 3 years ago

planetis-m commented 3 years ago

It's not an original idea, it was proposed by @Araq before, that automatic closing of resources can be made with destructors. But for some reason there wasn't any activity on it. Would it be ok to start as a first phase, the implementation of destructors for the streams module?. Any technical limitations or bugs blocking this task?

alaviss commented 3 years ago

The reason is simply: no one stepped up to do it yet. So I decided to crack on it with my experimental nim-sys package. I have uncovered some very annoying destructors bug though (all reported).

Ideally streams don't need destructors. Instead the lower-level primitives should have them, which will propengate the destructor to anything wrapping it, for example a FileStream wrapping File will inherit File destructors automatically.