From 0cc30bd39c730543d40747639a1434b8561f85e6 Mon Sep 17 00:00:00 2001 From: Cosmic Horror Date: Wed, 5 Apr 2023 08:32:16 -0600 Subject: [PATCH 1/4] Don't panic on drop --- src/frame/compress.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/frame/compress.rs b/src/frame/compress.rs index 8b4f23f..8d0cef1 100644 --- a/src/frame/compress.rs +++ b/src/frame/compress.rs @@ -401,9 +401,7 @@ pub struct AutoFinishEncoder { impl Drop for AutoFinishEncoder { fn drop(&mut self) { if let Some(mut encoder) = self.encoder.take() { - if let Err(err) = encoder.try_finish() { - panic!("Error when flushing frame on drop {:?} ", err); - } + let _ = encoder.try_finish(); } } } From 102288e94673c58a8c66afd308f2658016918f0b Mon Sep 17 00:00:00 2001 From: Cosmic Horror Date: Wed, 5 Apr 2023 08:42:04 -0600 Subject: [PATCH 2/4] Update docs --- src/frame/compress.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/frame/compress.rs b/src/frame/compress.rs index 8d0cef1..2e3bff3 100644 --- a/src/frame/compress.rs +++ b/src/frame/compress.rs @@ -112,10 +112,6 @@ impl FrameEncoder { } /// Returns a wrapper around `self` that will finish the stream on drop. - /// - /// # Panic - /// - /// Panics on drop if an error happens when finishing the stream. pub fn auto_finish(self) -> AutoFinishEncoder { AutoFinishEncoder { encoder: Some(self), From 10ecc5d5ab7564d8c5958665c9d125888a08b6b0 Mon Sep 17 00:00:00 2001 From: Cosmic Horror Date: Thu, 6 Apr 2023 17:19:19 -0600 Subject: [PATCH 3/4] Improve docs --- src/frame/compress.rs | 27 ++++++++++++++++++++++----- src/frame/mod.rs | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/frame/compress.rs b/src/frame/compress.rs index 2e3bff3..a061815 100644 --- a/src/frame/compress.rs +++ b/src/frame/compress.rs @@ -30,7 +30,11 @@ use crate::block::WINDOW_SIZE; /// writer in a `std::io::BufWriter`. /// /// To ensure a well formed stream the encoder must be finalized by calling -/// either `finish` or `try_finish()` methods. +/// either the [`finish()`], [`try_finish()`], or [`auto_finish()`] methods. +/// +/// [`finish()`]: Self::finish +/// [`try_finish()`]: Self::try_finish +/// [`auto_finish()`]: Self::auto_finish /// /// # Example 1 /// Serializing json values into a compressed file. @@ -112,6 +116,13 @@ impl FrameEncoder { } /// Returns a wrapper around `self` that will finish the stream on drop. + /// + /// # Note + /// Errors on drop get silently ignored. If you want to handle errors then use [`finish()`] or + /// [`try_finish()`] instead. + /// + /// [`finish()`]: Self::finish + /// [`try_finish()`]: Self::try_finish pub fn auto_finish(self) -> AutoFinishEncoder { AutoFinishEncoder { encoder: Some(self), @@ -383,12 +394,18 @@ impl io::Write for FrameEncoder { } } -/// A wrapper around an `FrameEncoder` that finishes the stream on drop. +/// A wrapper around an [`FrameEncoder`] that finishes the stream on drop. +/// +/// This can be created by the [`auto_finish()`] method on the [`FrameEncoder`]. /// -/// This can be created by the [`auto_finish()`] method on the [`FrameEncoder`]. +/// # Note +/// Errors on drop get silently ignored. If you want to handle errors then use [`finish()`] or +/// [`try_finish()`] instead. /// -/// [`auto_finish()`]: Encoder::auto_finish -/// [`Encoder`]: Encoder +/// [`finish()`]: FrameEncoder::finish +/// [`try_finish()`]: FrameEncoder::try_finish +/// [`auto_finish()`]: FrameEncoder::auto_finish +/// [`FrameEncoder`]: FrameEncoder pub struct AutoFinishEncoder { // We wrap this in an option to take it during drop. encoder: Option>, diff --git a/src/frame/mod.rs b/src/frame/mod.rs index 9cb484f..4a480e1 100644 --- a/src/frame/mod.rs +++ b/src/frame/mod.rs @@ -25,7 +25,7 @@ pub(crate) mod compress; pub(crate) mod decompress; pub(crate) mod header; -pub use compress::FrameEncoder; +pub use compress::{AutoFinishEncoder, FrameEncoder}; pub use decompress::FrameDecoder; pub use header::{BlockMode, BlockSize, FrameInfo}; From 0391f58b521d902764ffea76948da3ea763b3d86 Mon Sep 17 00:00:00 2001 From: PSeitz Date: Fri, 7 Apr 2023 15:36:56 +0200 Subject: [PATCH 4/4] Update src/frame/compress.rs --- src/frame/compress.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/frame/compress.rs b/src/frame/compress.rs index a061815..fd219e7 100644 --- a/src/frame/compress.rs +++ b/src/frame/compress.rs @@ -405,7 +405,6 @@ impl io::Write for FrameEncoder { /// [`finish()`]: FrameEncoder::finish /// [`try_finish()`]: FrameEncoder::try_finish /// [`auto_finish()`]: FrameEncoder::auto_finish -/// [`FrameEncoder`]: FrameEncoder pub struct AutoFinishEncoder { // We wrap this in an option to take it during drop. encoder: Option>,