Struct lzss::Lzss[][src]

pub struct Lzss<const EI: usize, const EJ: usize, const C: u8, const N: usize, const N2: usize>(_);
Expand description

A zero-sized type, the const generics specify the parameters of the compression.

Parameters

  • EI - The number of bits in the offset, usualy 10..13
  • EJ - The number of bits in the length, usually 4..5
  • C - The initial fill byte of the buffer, usually 0x20 (space)
  • N - Equals 1 << EI, the size of the buffer for Lzss::decompress()
  • N2 - Equals 2 << EI (N * 2), the size of the buffer for Lzss::compress()

Restrictions

  • EJ must be larger than 0
  • EI must be larger than EJ
  • EI + EJ must be at least 8
  • EI + EJ must be 24 or less
  • N must be equal to 1 << EI
  • N2 must be equal to 2 << EI (N * 2)

Limitations

Since it’s not possible to do const calculations on const generics all parameters have to be set.

With feature const_panic

All parameters are checked at compile-time.

There is no runtime overhead since everything is checked during compile-time.

Without feature const_panic

All parameters are checked at runtime.

There should be no runtime overhead since the compiler will replace the funtion with a panic if there is a problem. You just won’t notice that during compilation.

Example

type MyLzss = Lzss<10, 4, 0x20, { 1 << 10 }, { 2 << 10 }>;
let input = b"Example Data";
let mut output = [0; 14];
let result = MyLzss::compress(
  SliceReader::new(input),
  SliceWriterExact::new(&mut output),
);
assert!(result.is_ok()); // the output is exactly 14 bytes long

Implementations

Compress the input data into the output.

The buffer, with N2 bytes, is allocated on the stack.

alloc/std Compress the input data into the output.

The buffer, with N2 bytes, is allocated on the heap.

Compress the input data into the output.

Decompress the input data into the output.

The buffer, with N bytes, is allocated on the stack.

alloc/std Decompress the input data into the output.

The buffer, with N bytes, is allocated on the heap.

Decompress the input data into the output.

Compress, the input and output is in the same slice.

The input is located at io[offset..]. When there is enough space in the slice then the result will be (size, None). And the output is located at io[0..size].

If there is not enough space in the slice, i.e. the output (or buffer) would overwrite the input, then the result will be (size, Some(new_offset)), the already compressed data is in io[0..size] and the not yet compressed data is in io[new_offset..].

Even when the compression fails due to space the data is recoverable.

The minimum offset is Lzss::MIN_OFFSET, though if the offset is Lzss::MIN_OFFSET + input_size/8 then the compression can’t fail.

The minimal offset when using compress_in_place.

It’s a little less than N.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.