3 ms·
I agree it's a bit unfortunate. The rub here would be that `Drop` would become fallible, and if it is fallible, then … how does it fail, exactly? (What happens
by deathanatos 5y ago
I agree it's a bit unfortunate. The rub here would be that `Drop` would become fallible, and if it is fallible, then … how does it fail, exactly? (What happens to the error?)
There's exceptions, but the downsides to such systems are pretty extensively covered.
Nonetheless, the point here is that RAII offers a deterministic close compared to other approaches, at least, even if the write's success isn't covered. You can get that, too, with,
wordlist_file.flush()?;
or
wordlist_file.sync_all()?;
depending on desires.
(And again, I agree that requiring the programmer to remember code in order to obtain safe behavior is not desirable. But this problem manifests in pretty much any other language, and typically in worse manners.)
- deleted 5y ago[deleted]