Skip to main content

CompressionLevel

Enum CompressionLevel 

Source
pub enum CompressionLevel {
    Uncompressed,
    Fastest,
    Default,
    Better,
    Best,
    Level(i32),
}
Expand description

The compression mode used impacts the speed of compression, and resulting compression ratios. Faster compression will result in worse compression ratios, and vice versa.

Variants§

§

Uncompressed

This level does not compress the data at all, and simply wraps it in a Zstandard frame.

§

Fastest

This level is roughly equivalent to Zstd compression level 1

§

Default

This level uses the crate’s dedicated dfast-style matcher to target a better speed/ratio tradeoff than CompressionLevel::Fastest.

It represents this crate’s “default” compression setting and may evolve in future versions as the implementation moves closer to reference zstd level 3 behavior.

§

Better

This level is roughly equivalent to Zstd level 7.

Uses the hash-chain matcher with a lazy2 matching strategy: the encoder evaluates up to two positions ahead before committing to a match, trading speed for a better compression ratio than CompressionLevel::Default.

§

Best

This level is roughly equivalent to Zstd level 11.

Uses the hash-chain matcher with a deep lazy2 matching strategy and a 16 MiB window. Compared to CompressionLevel::Better, this level uses larger hash and chain tables (2 M / 1 M entries vs 1 M / 512 K), a deeper search (32 candidates vs 16), and a higher target match length (128 vs 48), trading speed for the best compression ratio available in this crate.

§

Level(i32)

Numeric compression level.

Levels 1–22 correspond to the C zstd level numbering. Higher values produce smaller output at the cost of more CPU time. Negative values select ultra-fast modes that trade ratio for speed. Level 0 is treated as DEFAULT_LEVEL, matching C zstd semantics.

Named variants map to specific numeric levels: Fastest = 1, Default = 3, Better = 7, Best = 11. Best remains the highest-ratio named preset, but Level values above 11 can target stronger (slower) tuning than the named hierarchy.

Levels above 11 use progressively larger windows and deeper search. Levels 16–17 use a btopt-style price parser, 18–19 use btultra, and 20–22 use a btultra2-style two-pass selection profile.

Semver note: this variant was added after the initial enum shape and is a breaking API change for downstream crates that exhaustively match on CompressionLevel without a wildcard arm.

Implementations§

Source§

impl CompressionLevel

Source

pub const MIN_LEVEL: i32 = -131072

The minimum supported numeric compression level (ultra-fast mode).

Source

pub const MAX_LEVEL: i32 = 22

The maximum supported numeric compression level.

Source

pub const DEFAULT_LEVEL: i32 = 3

The default numeric compression level (equivalent to Default).

Source

pub const fn from_level(level: i32) -> Self

Create a compression level from a numeric value.

Returns named variants for canonical levels (0/3, 1, 7, 11) and Level for all other values.

With the default matcher backend (MatchGeneratorDriver), values outside MIN_LEVEL..=MAX_LEVEL are silently clamped during built-in level parameter resolution.

Trait Implementations§

Source§

impl Clone for CompressionLevel

Source§

fn clone(&self) -> CompressionLevel

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompressionLevel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for CompressionLevel

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.