pub enum Compress {
Gzip,
Deflate,
Br,
Unknown,
}Variants§
Implementations§
Source§impl Compress
impl Compress
Sourcepub fn is_unknown(&self) -> bool
pub fn is_unknown(&self) -> bool
Checks if the current instance is of the Unknown type.
This method compares the current instance with the Unknown variant of the enum.
It returns true if the instance is of type Unknown, otherwise false.
§Returns
trueif the instance is of typeUnknown.falseotherwise.
Sourcepub fn from(
header: &HashMap<String, String, BuildHasherDefault<Hasher>>,
) -> Compress
pub fn from( header: &HashMap<String, String, BuildHasherDefault<Hasher>>, ) -> Compress
Extracts the compression type from an HTTP header.
This function looks for the Content-Encoding header in the provided Header and attempts
to parse it into a Compress enum value.
§Arguments
header- The HTTP header from which the compression type is to be extracted.
§Returns
- The
Compressvalue corresponding to theContent-Encodingheader, orCompress::Unknownif the header does not match any known compression types.
Sourcepub fn decode<'a>(&self, data: &'a [u8], buffer_size: usize) -> Cow<'a, Vec<u8>>
pub fn decode<'a>(&self, data: &'a [u8], buffer_size: usize) -> Cow<'a, Vec<u8>>
Decompresses the given data based on the selected compression algorithm.
This method takes a byte slice of compressed data and decompresses it using one of the following compression algorithms, depending on the variant of the enum it is called on:
Gzip- Decompresses using Gzip compression.Deflate- Decompresses using Deflate compression.Br- Decompresses using Brotli compression.Unknown- Returns the input data as-is (no decompression performed).
§Parameters
data- A reference to a byte slice (&[u8]) containing the compressed data to be decoded.buffer_size- The buffer size to use for the decompression process. A larger buffer size can improve performance for larger datasets.
§Returns
Cow<Vec<u8>>- The decompressed data as aCow<Vec<u8>>. If the compression algorithm isUnknown, the original data is returned unchanged, as a borrowed reference. Otherwise, the decompressed data is returned as an ownedVec<u8>.
Sourcepub fn encode<'a>(&self, data: &'a [u8], buffer_size: usize) -> Cow<'a, Vec<u8>>
pub fn encode<'a>(&self, data: &'a [u8], buffer_size: usize) -> Cow<'a, Vec<u8>>
Compresses the given data based on the selected compression algorithm.
This method takes a byte slice of data and compresses it using one of the following compression algorithms, depending on the variant of the enum it is called on:
Gzip- Compresses using Gzip compression.Deflate- Compresses using Deflate compression.Br- Compresses using Brotli compression.Unknown- Returns the input data as-is (no compression performed).
§Parameters
data- A reference to a byte slice (&[u8]) containing the data to be compressed.buffer_size- The buffer size to use for the compression process. A larger buffer size can improve performance for larger datasets.
§Returns
Cow<Vec<u8>>- The compressed data as aCow<Vec<u8>>. If the compression algorithm isUnknown, the original data is returned unchanged, as a borrowed reference. Otherwise, the compressed data is returned as an ownedVec<u8>.
Trait Implementations§
impl Eq for Compress
impl StructuralPartialEq for Compress
Auto Trait Implementations§
impl Freeze for Compress
impl RefUnwindSafe for Compress
impl Send for Compress
impl Sync for Compress
impl Unpin for Compress
impl UnwindSafe for Compress
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.