pub trait Compress {
// Required methods
fn compress(&self, block: Vec<u8>) -> Vec<u8> ⓘ;
fn decompress(&self, block: Vec<u8>) -> Result<Vec<u8>, ()>;
}Expand description
Provide your own compression algorithm by
creating an empty struct implementing compress
and decompress.
Your compression algorithm is allowed to fail, but must always decompress into the same bytes. Undefined behaviour otherwise.
Note: You must always also implement CompressBoxedClone, to allow cloning and debugging of the configuration.
use swapvec::Compress;
struct DummyCompression;
impl Compress for DummyCompression {
fn compress(&self, block: Vec<u8>) -> Vec<u8> {
block
}
fn decompress(&self, block: Vec<u8>) -> Result<Vec<u8>, ()> {
Ok(block)
}
}
let bytes = vec![1, 2, 3];
let compression = DummyCompression;
assert_eq!(bytes, compression.decompress(compression.compress(bytes.clone())).unwrap());