pub trait Compressor:
Send
+ Sync
+ Debug {
// Required methods
fn compress(&self, data: &[u8]) -> Result<Vec<u8>>;
fn decompress(&self, data: &[u8]) -> Result<Vec<u8>>;
fn decompress_into(&self, data: &[u8], out: &mut [u8]) -> Result<usize>;
// Provided method
fn compress_into(&self, data: &[u8], out: &mut Vec<u8>) -> Result<()> { ... }
}Expand description
Pluggable interface for block-oriented compressors.
Architectural intent: Allows snapshot writers and readers to operate against an abstraction rather than a specific compression library, making it possible to add or swap algorithms without touching the format layer.
Constraints: Implementations must be thread-safe and stateless or internally synchronized; all methods are expected to be pure functions of their inputs.
Required Methods§
Sourcefn compress(&self, data: &[u8]) -> Result<Vec<u8>>
fn compress(&self, data: &[u8]) -> Result<Vec<u8>>
Compresses data into an owned buffer.
Architectural intent: Encodes a single logical block using the compressor’s native framing.
Constraints: The caller is responsible for choosing an appropriate block size; extremely large inputs may cause excessive memory usage.
Sourcefn decompress(&self, data: &[u8]) -> Result<Vec<u8>>
fn decompress(&self, data: &[u8]) -> Result<Vec<u8>>
Decompresses an encoded block into a new buffer.
Architectural intent: Reverses compress, returning the original
block bytes or failing if corruption or format errors are detected.
Constraints: The input must have been produced by a compatible
encoder; malformed data must surface as a Error::Compression.
Sourcefn decompress_into(&self, data: &[u8], out: &mut [u8]) -> Result<usize>
fn decompress_into(&self, data: &[u8], out: &mut [u8]) -> Result<usize>
Decompresses an encoded block into a caller-provided buffer.
Architectural intent: Enables buffer reuse for hot paths to reduce allocation pressure.
Constraints: Implementations may fail if out is too small for the
decompressed payload; the return value is the number of bytes written.
Provided Methods§
Sourcefn compress_into(&self, data: &[u8], out: &mut Vec<u8>) -> Result<()>
fn compress_into(&self, data: &[u8], out: &mut Vec<u8>) -> Result<()>
Compresses data into a caller-provided buffer, enabling buffer reuse.
Architectural intent: Eliminates per-call allocation in hot write
paths by reusing a Vec across iterations.
Default impl: Falls back to compress() and copies the result.