matklad / xshell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consider adding a `fn finish(self) -> Result<()>` to RAII values

azdavis opened this issue · comments

There's a handful of things that do interesting things when dropped, like Pushd and Pushenv. However, their drop impls can fail.

We might want to add something like fn finish(self) -> Result<()> that can be called in user code that 'does the drop impl' but allows reporting errors instead of panicking/ignoring them.

We should also decide on whether we want to panic or ignore errors when dropping. std likes to ignore them and asserts 'dtors should not panic'.

One thing they do is asserting the absence of concurrent modificains. This checks for possible bugs in the code, and should not be elevated from panic to results.

Pushd calls set_current_dir, which can fail, so adding fn pop(self) -> Result<()> to pushd would be reasonable. I am a little unnerved that std doesn't actually document when this operation can fail, but I think it can fail if the dir is removed or chmoded.

As a nice benefit of the new impl, dtors are now infailable

nice!