Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! Rust binding to the [zstd library][zstd].
2 //!
3 //! This crate provides:
4 //!
5 //! * An [encoder](stream/write/struct.Encoder.html) to compress data using zstd
6 //! and send the output to another write.
7 //! * A [decoder](stream/read/struct.Decoder.html) to read input data from a `Read`
8 //! and decompress it.
9 //! * Convenient functions for common tasks.
10 //!
11 //! # Example
12 //!
13 //! ```no_run
14 //! use std::io;
15 //!
16 //! // Uncompress input and print the result.
17 //! zstd::stream::copy_decode(io::stdin(), io::stdout()).unwrap();
18 //! ```
19 //!
20 //! [zstd]: https://github.com/facebook/zstd
21 #![deny(missing_docs)]
22 #![cfg_attr(feature = "doc-cfg", feature(doc_cfg))]
23
24 // Re-export the zstd-safe crate.
25 pub use zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/;
26
27 pub mod bulkrust-analyzer cargo zstd 0.13.3 bulk/;
28 pub mod dictrust-analyzer cargo zstd 0.13.3 dict/;
29
30 #[macro_use]
31 pub mod streamrust-analyzer cargo zstd 0.13.3 stream/;
32
33 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/;
34
35 /// Default compression level.
36 pub use zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::CLEVEL_DEFAULTrust-analyzer cargo zstd-safe 7.2.2 CLEVEL_DEFAULT. as DEFAULT_COMPRESSION_LEVELrust-analyzer cargo zstd-safe 7.2.2 CLEVEL_DEFAULT.;
37
38 /// The accepted range of compression levels.
39 pub fn compression_level_rangerust-analyzer cargo zstd 0.13.3 compression_level_range().(
40 ) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::CompressionLevelrust-analyzer cargo zstd-safe 7.2.2 CompressionLevel#> {
41 zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::min_c_levelrust-analyzer cargo zstd-safe 7.2.2 min_c_level().()..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::max_c_levelrust-analyzer cargo zstd-safe 7.2.2 max_c_level().()
42 }
43
44 #[doc(no_inline)]
45 pub use craterust-analyzer cargo zstd 0.13.3 crate/::streamrust-analyzer cargo zstd 0.13.3 stream/::{decode_allrust-analyzer cargo zstd 0.13.3 stream/functions/decode_all()., encode_allrust-analyzer cargo zstd 0.13.3 stream/functions/encode_all()., Decoderrust-analyzer cargo zstd 0.13.3 stream/read/Decoder#, Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#};
46
47 /// Returns the error message as io::Error based on error_code.
48 fn map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().(code: usize) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error# {
49 let msg = zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::get_error_namerust-analyzer cargo zstd-safe 7.2.2 get_error_name().(code);
50 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#, msg.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
51 }
52
53 // Some helper functions to write full-cycle tests.
54
55 #[cfg(test)]
56 fn test_cyclerust-analyzer cargo zstd 0.13.3 test_cycle().<F, G>(data: &[u8], f: F, g: G)
57 where
58 F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&[u8]) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>,
59 G: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&[u8]) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>,
60 {
61 let mid = f(data);
62 let end = g(&mid);
63 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data, &end[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
64 }
65
66 #[cfg(test)]
67 fn test_cycle_unwraprust-analyzer cargo zstd 0.13.3 test_cycle_unwrap().<F, G>(data: &[u8], f: F, g: G)
68 where
69 F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>,
70 G: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>,
71 {
72 test_cyclerust-analyzer cargo zstd 0.13.3 test_cycle().(data, |data| f(data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |data| g(data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().())
73 }
74
75 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
76 fn default_compression_level_in_rangerust-analyzer cargo zstd 0.13.3 default_compression_level_in_range().() {
77 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(compression_level_rangerust-analyzer cargo zstd 0.13.3 compression_level_range().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&DEFAULT_COMPRESSION_LEVELrust-analyzer cargo zstd-safe 7.2.2 CLEVEL_DEFAULT.));
78 }