Closed ufoscout closed 1 year ago
I would say that this is out of scope for once_cell. Moreover, I would also argue that the best pattern in this case is to create resources explicitly in main and pass references down:
fn finialize(self) -> io::Result<()>
methods than to rely on implicit Drop
, which has no affordance for error reporting. @matklad I agree with every single word you said, anyway, my use case is explicitly about testing where I need to initialize something just once before all tests and to drop it at the end.
Closing: I think the way to solve this is to use something like https://crates.io/crates/shutdown_hooks, but that's better left to user-code/some other crate. I don't think this should be supported in once-cell proper.
I know that rust itself does not call
drop()
on static instances; however, I wonder if this could be supported byonce_cell
. My use case is that I need to clean some resources (e.g. stop a docker container) when the process exits. For example: