Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev authored and PSeitz committed Apr 7, 2023
1 parent 4b070ef commit a015e44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
27 changes: 22 additions & 5 deletions src/frame/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -112,6 +116,13 @@ impl<W: io::Write> FrameEncoder<W> {
}

/// 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<W> {
AutoFinishEncoder {
encoder: Some(self),
Expand Down Expand Up @@ -383,12 +394,18 @@ impl<W: io::Write> io::Write for FrameEncoder<W> {
}
}

/// A wrapper around an `FrameEncoder<W>` that finishes the stream on drop.
/// A wrapper around an [`FrameEncoder<W>`] that finishes the stream on drop.
///
/// This can be created by the [`auto_finish()`] method on the [`FrameEncoder<W>`].
///
/// 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<W>`]: FrameEncoder
pub struct AutoFinishEncoder<W: Write> {
// We wrap this in an option to take it during drop.
encoder: Option<FrameEncoder<W>>,
Expand Down
2 changes: 1 addition & 1 deletion src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down

0 comments on commit a015e44

Please sign in to comment.