diff --git a/src/frame/compress.rs b/src/frame/compress.rs index 8b4f23f..fd219e7 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. @@ -113,9 +117,12 @@ impl FrameEncoder { /// Returns a wrapper around `self` that will finish the stream on drop. /// - /// # Panic + /// # Note + /// Errors on drop get silently ignored. If you want to handle errors then use [`finish()`] or + /// [`try_finish()`] instead. /// - /// Panics on drop if an error happens when finishing the stream. + /// [`finish()`]: Self::finish + /// [`try_finish()`]: Self::try_finish pub fn auto_finish(self) -> AutoFinishEncoder { AutoFinishEncoder { encoder: Some(self), @@ -387,12 +394,17 @@ 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 pub struct AutoFinishEncoder { // We wrap this in an option to take it during drop. encoder: Option>, @@ -401,9 +413,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(); } } } 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};