1//! This module contains backend-specific code.
2
3use crate::mem::{CompressError, DecompressError, FlushCompress, FlushDecompress, Status};
4use crate::Compression;
5
6/// Traits specifying the interface of the backends.
7///
8/// Sync + Send are added as a condition to ensure they are available
9/// for the frontend.
10pub trait Backend: Sync + Send {
11 fn total_in(&self) -> u64;
12 fn total_out(&self) -> u64;
13}
14
15pub trait InflateBackend: Backend {
16 fn make(zlib_header: bool, window_bits: u8) -> Self;
17 fn decompress(
18 &mut self,
19 input: &[u8],
20 output: &mut [u8],
21 flush: FlushDecompress,
22 ) -> Result<Status, DecompressError>;
23 fn reset(&mut self, zlib_header: bool);
24}
25
26pub trait DeflateBackend: Backend {
27 fn make(level: Compression, zlib_header: bool, window_bits: u8) -> Self;
28 fn compress(
29 &mut self,
30 input: &[u8],
31 output: &mut [u8],
32 flush: FlushCompress,
33 ) -> Result<Status, CompressError>;
34 fn reset(&mut self);
35}
36
37// Default to Rust implementation unless explicitly opted in to a different backend.
38#[cfg(feature = "any_zlib")]
39mod c;
40#[cfg(feature = "any_zlib")]
41pub use self::c::*;
42
43#[cfg(not(feature = "any_zlib"))]
44mod rust;
45#[cfg(not(feature = "any_zlib"))]
46pub use self::rust::*;
47
48impl std::fmt::Debug for ErrorMessage {
49 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
50 self.get().fmt(f)
51 }
52}
53