maili_protocol/compression/traits.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
//! Contains the core `Compressor` trait.
use crate::CompressorResult;
use alloc::vec::Vec;
/// Compressor Writer
///
/// A trait that expands the standard library `Write` trait to include
/// compression-specific methods and return [CompressorResult] instead of
/// standard library `Result`.
#[allow(clippy::len_without_is_empty)]
pub trait CompressorWriter {
/// Writes the given data to the compressor.
fn write(&mut self, data: &[u8]) -> CompressorResult<usize>;
/// Flushes the buffer.
fn flush(&mut self) -> CompressorResult<()>;
/// Closes the compressor.
fn close(&mut self) -> CompressorResult<()>;
/// Resets the compressor.
fn reset(&mut self);
/// Returns the length of the compressed data.
fn len(&self) -> usize;
/// Reads the compressed data into the given buffer.
/// Returns the number of bytes read.
fn read(&mut self, buf: &mut [u8]) -> CompressorResult<usize>;
}
/// Channel Compressor
///
/// A compressor for channels.
pub trait ChannelCompressor: CompressorWriter {
/// Returns the compressed data buffer.
fn get_compressed(&self) -> Vec<u8>;
}