summaryrefslogtreecommitdiffstats
path: root/third_party/rust/flate2/src/ffi/mod.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/flate2/src/ffi/mod.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/flate2/src/ffi/mod.rs')
-rw-r--r--third_party/rust/flate2/src/ffi/mod.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/third_party/rust/flate2/src/ffi/mod.rs b/third_party/rust/flate2/src/ffi/mod.rs
new file mode 100644
index 0000000000..8bac6e4232
--- /dev/null
+++ b/third_party/rust/flate2/src/ffi/mod.rs
@@ -0,0 +1,52 @@
+//! This module contains backend-specific code.
+
+use crate::mem::{CompressError, DecompressError, FlushCompress, FlushDecompress, Status};
+use crate::Compression;
+
+/// Traits specifying the interface of the backends.
+///
+/// Sync + Send are added as a condition to ensure they are available
+/// for the frontend.
+pub trait Backend: Sync + Send {
+ fn total_in(&self) -> u64;
+ fn total_out(&self) -> u64;
+}
+
+pub trait InflateBackend: Backend {
+ fn make(zlib_header: bool, window_bits: u8) -> Self;
+ fn decompress(
+ &mut self,
+ input: &[u8],
+ output: &mut [u8],
+ flush: FlushDecompress,
+ ) -> Result<Status, DecompressError>;
+ fn reset(&mut self, zlib_header: bool);
+}
+
+pub trait DeflateBackend: Backend {
+ fn make(level: Compression, zlib_header: bool, window_bits: u8) -> Self;
+ fn compress(
+ &mut self,
+ input: &[u8],
+ output: &mut [u8],
+ flush: FlushCompress,
+ ) -> Result<Status, CompressError>;
+ fn reset(&mut self);
+}
+
+// Default to Rust implementation unless explicitly opted in to a different backend.
+#[cfg(feature = "any_zlib")]
+mod c;
+#[cfg(feature = "any_zlib")]
+pub use self::c::*;
+
+#[cfg(not(feature = "any_zlib"))]
+mod rust;
+#[cfg(not(feature = "any_zlib"))]
+pub use self::rust::*;
+
+impl std::fmt::Debug for ErrorMessage {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ self.get().fmt(f)
+ }
+}