Compression

Enum Compression 

Source
pub enum Compression {
    Disabled,
    Dedicated,
    Shared,
    Window256B,
    Window1KB,
    Window2KB,
    Window4KB,
    Window8KB,
    Window16KB,
    Window32KB,
}
Expand description

Compression mode for WebSocket connections (RFC 7692 permessage-deflate)

This enum controls how compression is handled for WebSocket connections.

Per RFC 7692, the LZ77 sliding window size is limited to 8-15 bits (256 bytes to 32KB). Larger windows provide better compression but use more memory per connection.

§Memory Usage per Connection

ModeDescriptionWindow BitsWindow Size
DisabledNo compression--
DedicatedPer-connection compressor1532KB
SharedShared compressor pool1532KB
Window256BMinimal memory8256B
Window1KB1KB sliding window101KB
Window2KB2KB sliding window112KB
Window4KB4KB sliding window124KB
Window8KB8KB sliding window138KB
Window16KB16KB sliding window1416KB
Window32KB32KB sliding window (max)1532KB

Variants§

§

Disabled

No compression

§

Dedicated

Dedicated compressor per connection (32KB window, best compression)

§

Shared

Shared compressor pool (32KB window, good for many connections)

§

Window256B

256 byte sliding window (window_bits=8, minimal memory)

§

Window1KB

1KB sliding window (window_bits=10)

§

Window2KB

2KB sliding window (window_bits=11)

§

Window4KB

4KB sliding window (window_bits=12)

§

Window8KB

8KB sliding window (window_bits=13)

§

Window16KB

16KB sliding window (window_bits=14)

§

Window32KB

32KB sliding window (window_bits=15, maximum per RFC 7692)

Implementations§

Source§

impl Compression

Source

pub fn is_enabled(&self) -> bool

Returns true if compression is enabled

Source

pub fn is_shared(&self) -> bool

Returns true if this mode uses shared compression

Source

pub fn is_dedicated(&self) -> bool

Returns true if this mode uses dedicated per-connection compression

Source

pub fn window_bits(&self) -> u8

Get the window bits for this compression mode

Returns the LZ77 window bits (8-15) for RFC 7692 compliance.

Source

pub fn compression_threshold(&self) -> usize

Get the compression threshold for this mode

Messages smaller than this threshold won’t be compressed. Larger window modes benefit more from compressing smaller messages.

Source

pub fn context_takeover(&self) -> bool

Whether to use context takeover (preserve compression dictionary between messages)

Smaller window modes disable context takeover to reduce memory. Shared mode also disables context takeover since the encoder pool cannot maintain context across different connections. Larger dedicated modes enable it for better compression across messages.

Source

pub fn to_deflate_config(&self) -> Option<DeflateConfig>

Convert to DeflateConfig

Trait Implementations§

Source§

impl Clone for Compression

Source§

fn clone(&self) -> Compression

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Compression

Source§

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

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

impl Default for Compression

Source§

fn default() -> Compression

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Compression

Source§

fn eq(&self, other: &Compression) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Compression

Source§

impl Eq for Compression

Source§

impl StructuralPartialEq for Compression

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> Same for T

Source§

type Output = T

Should always be Self
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.