pub struct WindowSize(/* private fields */);
Expand description
The sliding window size (in bits) to use for compression.
Its maximum size is currently limited to 16 MiB, as specified in RFC7932
(Brotli proper). Larger window sizes are supported via LargeWindowSize
,
however note that decompression support for these have to be explicitly
enabled. This can be configured via large_window_size
for the matching
BrotliDecoder
.
Implementations§
Source§impl WindowSize
impl WindowSize
Sourcepub const fn new(bits: u8) -> Result<WindowSize, SetParameterError>
pub const fn new(bits: u8) -> Result<WindowSize, SetParameterError>
Constructs a new sliding window size to use for brotli compression.
Valid bits
range from 10 (1 KiB) to 24 (16 MiB) inclusive.
§Errors
An Err
will be returned if the bits
are out of the range of valid
window sizes.
§Examples
use brotlic::WindowSize;
let worst_size = WindowSize::new(10)?;
let best_size = WindowSize::new(24)?;
assert_eq!(worst_size, WindowSize::worst());
assert_eq!(best_size, WindowSize::best());
Sourcepub const unsafe fn new_unchecked(bits: u8) -> WindowSize
pub const unsafe fn new_unchecked(bits: u8) -> WindowSize
Constructs a new sliding window size (in bits) to use for brotli compression.
Valid bits
range from 10 (1 KiB) to 24 (16 MiB) inclusive. Using a
number of bits
outside of that range results in undefined
behaviour.
§Safety
The number of bits
must be between 10 and 24.
§Examples
use brotlic::WindowSize;
// SAFETY: 23 is within the valid range of 10 to 24 in window sizes
let window_size = unsafe { WindowSize::new_unchecked(23) };
assert_eq!(window_size.bits(), 23);
Sourcepub const fn best() -> WindowSize
pub const fn best() -> WindowSize
Constructs the best sliding window size to use for brotli compression.
This is currently limited to 24 bits (16 MiB) due to RFC7932 (Brotli
proper). To use larger sliding window sizes, please refer to
LargeWindowSize
. Note however that explicit support has to be
enabled by the decoder. This is supported by enabling
large_window_size
when constructing a BrotliDecoder
.
§Examples
use brotlic::WindowSize;
let best_size = WindowSize::new(24)?;
assert_eq!(best_size, WindowSize::best());
Sourcepub const fn default() -> WindowSize
pub const fn default() -> WindowSize
Constructs the default sliding window size to use for brotli compression.
This is currently set to 22 bits (4 MiB).
§Examples
use brotlic::WindowSize;
let default_size = WindowSize::new(22)?;
assert_eq!(default_size, WindowSize::default());
Sourcepub const fn worst() -> WindowSize
pub const fn worst() -> WindowSize
Constructs the worst sliding window size to use for brotli compression
This is currently set to 10 bits (1 KiB).
§Examples
use brotlic::WindowSize;
let worst_size = WindowSize::new(10)?;
assert_eq!(worst_size, WindowSize::worst());
Trait Implementations§
Source§impl Clone for WindowSize
impl Clone for WindowSize
Source§fn clone(&self) -> WindowSize
fn clone(&self) -> WindowSize
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for WindowSize
impl Debug for WindowSize
Source§impl Default for WindowSize
impl Default for WindowSize
Source§fn default() -> WindowSize
fn default() -> WindowSize
Creates a new WindowSize
using default
.
See its documentation for more.
Source§impl Ord for WindowSize
impl Ord for WindowSize
Source§fn cmp(&self, other: &WindowSize) -> Ordering
fn cmp(&self, other: &WindowSize) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for WindowSize
impl PartialEq for WindowSize
Source§impl PartialOrd for WindowSize
impl PartialOrd for WindowSize
Source§impl TryFrom<LargeWindowSize> for WindowSize
impl TryFrom<LargeWindowSize> for WindowSize
Source§fn try_from(
large_window_size: LargeWindowSize,
) -> Result<WindowSize, <WindowSize as TryFrom<LargeWindowSize>>::Error>
fn try_from( large_window_size: LargeWindowSize, ) -> Result<WindowSize, <WindowSize as TryFrom<LargeWindowSize>>::Error>
Attempts to construct a WindowSize
from a LargeWindowSize
.
This only works if the large window size is currently set to a value
lower or equal to WindowSize::best()
.
§Errors
Large window size does not fit into a window size.