-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't panic on drop #100
Don't panic on drop #100
Conversation
Codecov Report
@@ Coverage Diff @@
## main #100 +/- ##
==========================================
- Coverage 89.39% 88.53% -0.87%
==========================================
Files 11 11
Lines 2179 2189 +10
==========================================
- Hits 1948 1938 -10
- Misses 231 251 +20
... and 2 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Here's the other branch I'm talking about above https://github.com/CosmicHorrorDev/lz4_flex/tree/remove-AutoFinishEncoder And here are the benchmark results for
|
Thanks! Shouldn't we at least print the error if something goes wrong? I wouldn't have excepted such a large performance regression by wrapping the witer |
I know the The standard library typically just accepts that things will silently fail on
It's also easy enough for people to make their own wrapper that gives them better observability struct LogOnDrop(FrameEncoder<File>);
impl Drop for LogOnDrop {
fn drop(&mut self) {
if let Err(e) = self.0.try_finish() {
log::warn!("Failed finishing: {e}");
}
}
} People can just use the finalization methods if they need to see that there is an error. Relying on drop for this kind of stuff always hinders how you can convey failures |
Okay, then let's document that, so users are aware they can't blindly use |
Sounds good! I'll work on the documentation later today |
I tweaked a lot of the documentation. Let me know if that's more to your liking |
Yes, thanks! |
This makes the
Drop
impl forAutoFinishEncoder<_>
infallible. Panicking ondrop
is a very easy way to cause a program to abort since drop impls run while unwinding a panic which can cause a panic while already panickingI tried making
Encoder
automatically call.try_finish()
on drop, so thatAutoFinishEncoder<_>
wouldn't be needed in the first place, but my implementation probably regressed performance too much for your liking even though running finalization on drop is common (seezip
,xz2
, etc). I'll keep toying around with it to see if I can figure out the cause of the only severe regression (FrameCompress/lz4_flex_rust_(indep|linked)/66675
). It goes with the common technique of wrapping the writer in anOption<_>
, so that it can be.take
n by methods like.into_inner()
while still providing a drop impl