structured_zstd/lib.rs
1//! Pure-Rust Zstandard codec with a production-grade decoder, dictionary
2//! handle reuse, and an actively-improved encoder.
3//!
4//! The crate ships:
5//!
6//! * [`decoding`] — [RFC 8878] decoder ([`decoding::StreamingDecoder`],
7//! [`decoding::FrameDecoder`], dictionary-backed paths via
8//! [`decoding::DictionaryHandle`]).
9//! * [`encoding`] — frame compressor, streaming encoder, named and numeric
10//! compression levels ([`encoding::CompressionLevel`]).
11//! * [`dictionary`] (feature `dict_builder`) — COVER / FastCOVER training
12//! plus raw-to-finalized dictionary helpers.
13//!
14//! No FFI, no cmake, no system zstd. `no_std` builds are supported by
15//! disabling the default `std` feature.
16//!
17//! The packaged README is included below for the docs.rs landing page; the
18//! API anchors above link straight into the per-module documentation.
19//!
20//! [RFC 8878]: https://www.rfc-editor.org/rfc/rfc8878
21// Keep crate docs aligned with the packaged README via the crate-local symlink in `zstd/README.md`.
22#![doc = include_str!("../README.md")]
23#![no_std]
24#![deny(trivial_casts, trivial_numeric_casts, rust_2018_idioms)]
25#![cfg_attr(docsrs, feature(doc_cfg))]
26
27#[cfg(feature = "std")]
28extern crate std;
29
30#[cfg(not(feature = "rustc-dep-of-std"))]
31extern crate alloc;
32
33#[cfg(feature = "std")]
34pub(crate) const VERBOSE: bool = false;
35
36macro_rules! vprintln {
37 ($($x:expr),*) => {
38 #[cfg(feature = "std")]
39 if crate::VERBOSE {
40 std::println!($($x),*);
41 }
42 }
43}
44
45mod bit_io;
46mod common;
47pub mod decoding;
48#[cfg(feature = "dict_builder")]
49#[cfg_attr(docsrs, doc(cfg(feature = "dict_builder")))]
50pub mod dictionary;
51pub mod encoding;
52mod histogram;
53
54pub(crate) mod blocks;
55
56#[cfg(feature = "fuzz_exports")]
57pub mod fse;
58#[cfg(feature = "fuzz_exports")]
59pub mod huff0;
60
61#[cfg(not(feature = "fuzz_exports"))]
62pub(crate) mod fse;
63#[cfg(not(feature = "fuzz_exports"))]
64pub(crate) mod huff0;
65
66#[cfg(feature = "std")]
67pub mod io_std;
68
69#[cfg(feature = "std")]
70pub use io_std as io;
71
72#[cfg(not(feature = "std"))]
73pub mod io_nostd;
74
75#[cfg(not(feature = "std"))]
76pub use io_nostd as io;
77
78#[cfg(test)]
79mod tests;
80
81/// Re-exports of internal types used by benchmarks.
82///
83/// Gated behind the `bench_internals` feature so normal builds do not
84/// widen the public API surface. Not part of the stable API; items may
85/// change or disappear without notice.
86#[cfg(feature = "bench_internals")]
87#[doc(hidden)]
88pub mod testing {
89 pub use crate::bit_io::BitReaderReversed;
90
91 /// Bench-only facade for the decoder wildcopy implementation.
92 ///
93 /// # Safety
94 /// Caller must satisfy the same safety contract as
95 /// `decoding::copy_bytes_overshooting_for_bench`.
96 #[inline(always)]
97 pub unsafe fn copy_bytes_overshooting_for_bench(
98 src: (*const u8, usize),
99 dst: (*mut u8, usize),
100 copy_at_least: usize,
101 ) {
102 // Keep decoder internals crate-private and expose only this bench shim.
103 unsafe { crate::decoding::copy_bytes_overshooting_for_bench(src, dst, copy_at_least) };
104 }
105}