]> git.proxmox.com Git - cargo.git/blobdiff - vendor/miniz_oxide/src/lib.rs
New upstream version 0.63.1
[cargo.git] / vendor / miniz_oxide / src / lib.rs
index d459fe6a7043f0d0a735aec5c62a22bef8fa7854..8357c52006b05fb5c4b12be224148c90be98eb60 100644 (file)
 //!
 //! ```
 
-#![allow(warnings)]
 #![forbid(unsafe_code)]
-#![cfg_attr(any(has_alloc, feature = "rustc-dep-of-std"), no_std)]
+#![no_std]
 
-// autocfg does not work when building in libstd, so manually enable this for that use case now.
-#[cfg(any(has_alloc, feature = "rustc-dep-of-std"))]
 extern crate alloc;
-#[cfg(all(not(has_alloc), not(feature = "rustc-dep-of-std")))]
-use std as alloc;
-
-#[cfg(test)]
-extern crate std;
 
 pub mod deflate;
 pub mod inflate;
@@ -43,7 +35,7 @@ pub use crate::shared::{MZ_ADLER32_INIT, MZ_DEFAULT_WINDOW_BITS};
 
 /// A list of flush types.
 ///
-/// See [http://www.bolet.org/~pornin/deflate-flush.html] for more in-depth info.
+/// See <http://www.bolet.org/~pornin/deflate-flush.html> for more in-depth info.
 #[repr(i32)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub enum MZFlush {
@@ -51,14 +43,15 @@ pub enum MZFlush {
     /// Used when more input data is expected.
     None = 0,
     /// Zlib partial flush.
-    /// Currently treated as `Sync`.
+    /// Currently treated as [`Sync`].
     Partial = 1,
     /// Finish compressing the currently buffered data, and output an empty raw block.
     /// Has no use in decompression.
     Sync = 2,
-    /// Same as `Sync`, but resets the compression dictionary so that further compressed
+    /// Same as [`Sync`], but resets the compression dictionary so that further compressed
     /// data does not depend on data compressed before the flush.
-    /// Has no use in decompression.
+    ///
+    /// Has no use in decompression, and is an error to supply in that case.
     Full = 3,
     /// Attempt to flush the remaining data and end the stream.
     Finish = 4,
@@ -82,32 +75,80 @@ impl MZFlush {
 }
 
 /// A list of miniz successful status codes.
+///
+/// These are emitted as the [`Ok`] side of a [`MZResult`] in the [`StreamResult`] returned from
+/// [`deflate::stream::deflate()`] or [`inflate::stream::inflate()`].
 #[repr(i32)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub enum MZStatus {
+    /// Operation succeeded.
+    ///
+    /// Some data was decompressed or compressed; see the byte counters in the [`StreamResult`] for
+    /// details.
     Ok = 0,
+
+    /// Operation succeeded and end of deflate stream was found.
+    ///
+    /// X-ref [`TINFLStatus::Done`][inflate::TINFLStatus::Done] or
+    /// [`TDEFLStatus::Done`][deflate::core::TDEFLStatus::Done] for `inflate` or `deflate`
+    /// respectively.
     StreamEnd = 1,
+
+    /// Unused
     NeedDict = 2,
 }
 
 /// A list of miniz failed status codes.
+///
+/// These are emitted as the [`Err`] side of a [`MZResult`] in the [`StreamResult`] returned from
+/// [`deflate::stream::deflate()`] or [`inflate::stream::inflate()`].
 #[repr(i32)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub enum MZError {
+    /// Unused
     ErrNo = -1,
+
+    /// General stream error.
+    ///
+    /// See [`inflate::stream::inflate()`] docs for details of how it can occur there.
+    ///
+    /// See [`deflate::stream::deflate()`] docs for how it can in principle occur there, though it's
+    /// believed impossible in practice.
     Stream = -2,
+
+    /// Error in inflation; see [`inflate::stream::inflate()`] for details.
+    ///
+    /// Not returned from [`deflate::stream::deflate()`].
     Data = -3,
+
+    /// Unused
     Mem = -4,
+
+    /// Buffer-related error.
+    ///
+    /// See the docs of [`deflate::stream::deflate()`] or [`inflate::stream::inflate()`] for details
+    /// of when it would trigger in the one you're using.
     Buf = -5,
+
+    /// Unused
     Version = -6,
+
+    /// Bad parameters.
+    ///
+    /// This can be returned from [`deflate::stream::deflate()`] in the case of bad parameters.  See
+    /// [`TDEFLStatus::BadParam`][deflate::core::TDEFLStatus::BadParam].
     Param = -10_000,
 }
 
 /// How compressed data is wrapped.
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+#[non_exhaustive]
 pub enum DataFormat {
     /// Wrapped using the [zlib](http://www.zlib.org/rfc-zlib.html) format.
     Zlib,
+    /// Zlib wrapped but ignore and don't compute the adler32 checksum.
+    /// Currently only used for inflate, behaves the same as Zlib for compression.
+    ZLibIgnoreChecksum,
     /// Raw DEFLATE.
     Raw,
 }
@@ -123,7 +164,7 @@ impl DataFormat {
 
     pub(crate) fn to_window_bits(self) -> i32 {
         match self {
-            DataFormat::Zlib => shared::MZ_DEFAULT_WINDOW_BITS,
+            DataFormat::Zlib | DataFormat::ZLibIgnoreChecksum => shared::MZ_DEFAULT_WINDOW_BITS,
             DataFormat::Raw => -shared::MZ_DEFAULT_WINDOW_BITS,
         }
     }
@@ -145,7 +186,7 @@ pub struct StreamResult {
 
 impl StreamResult {
     #[inline]
-    pub(crate) fn error(error: MZError) -> StreamResult {
+    pub(crate) const fn error(error: MZError) -> StreamResult {
         StreamResult {
             bytes_consumed: 0,
             bytes_written: 0,