Struct lzss::Lzss

source ·
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, usually 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)

All parameters are checked at compile-time.

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

Limitations

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

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_stack(
  SliceReader::new(input),
  SliceWriterExact::new(&mut output),
);
assert!(result.is_ok()); // the output is exactly 14 bytes long

Implementations§

source§

impl<const EI: usize, const EJ: usize, const C: u8, const N: usize, const N2: usize> Lzss<EI, EJ, C, N, N2>

source

pub const fn as_dyn() -> LzssDyn

Create a new LzssDyn with the parameter from this generic type.

This is mainly useful for creating const LzssDyn.

type MyLzss = Lzss<10, 4, 0x20, { 1 << 10 }, { 2 << 10 }>;
const MY_DYN1: LzssDyn = MyLzss::as_dyn();
// or
const MY_DYN2: LzssDyn = Lzss::<10, 4, 0x20, { 1 << 10 }, { 2 << 10 }>::as_dyn();
source

pub fn compress<R: Read, W: Write>( reader: R, writer: W ) -> Result<W::Output, LzssError<R::Error, W::Error>>

👎Deprecated since 0.9.0: renamed to compress_stack

Compress the input data into the output.

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

source

pub fn compress_stack<R: Read, W: Write>( reader: R, writer: W ) -> Result<W::Output, LzssError<R::Error, W::Error>>

Compress the input data into the output.

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

source

pub fn compress_heap<R: Read, W: Write>( reader: R, writer: W ) -> Result<W::Output, LzssError<R::Error, W::Error>>

Available on crate features alloc or std only.

Compress the input data into the output.

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

source

pub fn compress_with_buffer<R: Read, W: Write>( reader: R, writer: W, buffer: &mut [u8; N2] ) -> Result<W::Output, LzssError<R::Error, W::Error>>

Compress the input data into the output.

source

pub fn decompress<R: Read, W: Write>( reader: R, writer: W ) -> Result<W::Output, LzssError<R::Error, W::Error>>

👎Deprecated since 0.9.0: renamed to decompress_stack

Decompress the input data into the output.

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

source

pub fn decompress_stack<R: Read, W: Write>( reader: R, writer: W ) -> Result<W::Output, LzssError<R::Error, W::Error>>

Decompress the input data into the output.

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

source

pub fn decompress_heap<R: Read, W: Write>( reader: R, writer: W ) -> Result<W::Output, LzssError<R::Error, W::Error>>

Available on crate features alloc or std only.

Decompress the input data into the output.

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

source

pub fn decompress_with_buffer<R: Read, W: Write>( reader: R, writer: W, buffer: &mut [u8; N] ) -> Result<W::Output, LzssError<R::Error, W::Error>>

Decompress the input data into the output.

source

pub fn compress_in_place(io: &mut [u8], offset: usize) -> (usize, Option<usize>)

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.

source

pub const MIN_OFFSET: usize = _

The minimal offset when using compress_in_place.

It’s a little less than N.

Auto Trait Implementations§

§

impl<const EI: usize, const EJ: usize, const C: u8, const N: usize, const N2: usize> RefUnwindSafe for Lzss<EI, EJ, C, N, N2>

§

impl<const EI: usize, const EJ: usize, const C: u8, const N: usize, const N2: usize> Send for Lzss<EI, EJ, C, N, N2>

§

impl<const EI: usize, const EJ: usize, const C: u8, const N: usize, const N2: usize> Sync for Lzss<EI, EJ, C, N, N2>

§

impl<const EI: usize, const EJ: usize, const C: u8, const N: usize, const N2: usize> Unpin for Lzss<EI, EJ, C, N, N2>

§

impl<const EI: usize, const EJ: usize, const C: u8, const N: usize, const N2: usize> UnwindSafe for Lzss<EI, EJ, C, N, N2>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.