Compress

Trait Compress 

Source
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());

Required Methods§

Source

fn compress(&self, block: Vec<u8>) -> Vec<u8>

Compress bytes blockwise. The compressed block will be put into self.decompress() later.

Source

fn decompress(&self, block: Vec<u8>) -> Result<Vec<u8>, ()>

Receive block which was earlier compress()ed. If the result is Ok, the same bytes which were compress()es earlier are expected.

Implementations on Foreign Types§

Source§

impl Compress for Option<Compression>

Source§

fn compress(&self, block: Vec<u8>) -> Vec<u8>

Source§

fn decompress(&self, block: Vec<u8>) -> Result<Vec<u8>, ()>

Implementors§