Skip to main content

structured_zstd/
lib.rs

1//! A pure Rust implementation of the [Zstandard compression format](https://www.rfc-editor.org/rfc/rfc8878.pdf).
2//!
3//! ## Decompression
4//! The [decoding] module contains the code for decompression.
5//! Decompression can be achieved by using the [`decoding::StreamingDecoder`]
6//! or the more low-level [`decoding::FrameDecoder`]
7//!
8//! ## Compression
9//! The [encoding] module contains the code for compression.
10//! Compression can be achieved by using the [`encoding::compress`]/[`encoding::compress_to_vec`]
11//! functions or [`encoding::FrameCompressor`]
12// Keep crate docs aligned with the packaged README via the crate-local symlink in `zstd/README.md`.
13#![doc = include_str!("../README.md")]
14#![no_std]
15#![deny(trivial_casts, trivial_numeric_casts, rust_2018_idioms)]
16
17#[cfg(feature = "std")]
18extern crate std;
19
20#[cfg(not(feature = "rustc-dep-of-std"))]
21extern crate alloc;
22
23#[cfg(feature = "std")]
24pub(crate) const VERBOSE: bool = false;
25
26macro_rules! vprintln {
27    ($($x:expr),*) => {
28        #[cfg(feature = "std")]
29        if crate::VERBOSE {
30            std::println!($($x),*);
31        }
32    }
33}
34
35mod bit_io;
36mod common;
37pub mod decoding;
38#[cfg(feature = "dict_builder")]
39#[cfg_attr(docsrs, doc(cfg(feature = "dict_builder")))]
40pub mod dictionary;
41pub mod encoding;
42mod histogram;
43
44pub(crate) mod blocks;
45
46#[cfg(feature = "fuzz_exports")]
47pub mod fse;
48#[cfg(feature = "fuzz_exports")]
49pub mod huff0;
50
51#[cfg(not(feature = "fuzz_exports"))]
52pub(crate) mod fse;
53#[cfg(not(feature = "fuzz_exports"))]
54pub(crate) mod huff0;
55
56#[cfg(feature = "std")]
57pub mod io_std;
58
59#[cfg(feature = "std")]
60pub use io_std as io;
61
62#[cfg(not(feature = "std"))]
63pub mod io_nostd;
64
65#[cfg(not(feature = "std"))]
66pub use io_nostd as io;
67
68mod tests;
69
70/// Re-exports of internal types used by benchmarks.
71///
72/// Gated behind the `bench_internals` feature so normal builds do not
73/// widen the public API surface. Not part of the stable API; items may
74/// change or disappear without notice.
75#[cfg(feature = "bench_internals")]
76#[doc(hidden)]
77pub mod testing {
78    pub use crate::bit_io::BitReaderReversed;
79
80    /// Bench-only facade for the decoder wildcopy implementation.
81    ///
82    /// # Safety
83    /// Caller must satisfy the same safety contract as
84    /// `decoding::copy_bytes_overshooting_for_bench`.
85    #[inline(always)]
86    pub unsafe fn copy_bytes_overshooting_for_bench(
87        src: (*const u8, usize),
88        dst: (*mut u8, usize),
89        copy_at_least: usize,
90    ) {
91        // Keep decoder internals crate-private and expose only this bench shim.
92        unsafe { crate::decoding::copy_bytes_overshooting_for_bench(src, dst, copy_at_least) };
93    }
94}