Skip to main content

EncoderDictionary

Struct EncoderDictionary 

Source
pub struct EncoderDictionary { /* private fields */ }
Expand description

A dictionary prepared for compression at a level (libzstd’s ZSTD_CDict, ZSTD_createCDict): parsed and indexed once, then used by any number of Compressors, StreamEncoders and Encoders (cloning it is cheap: the tables are shared). Frames compressed with it take its level, and are byte-identical to libzstd’s with the same CDict (ZSTD_CCtx_refCDict, the zstd crate’s with_prepared_dictionary).

Like libzstd’s ZSTD_dct_auto, data that starts with the dictionary magic number (0xEC30A437) is a zstd-format dictionary (as made by zstd --train: ID, entropy tables, repcodes, content), anything else raw content. Dictionaries under 8 bytes are ignored (no ID, no content).

use zstd_native::{Compressor, EncoderDictionary};

let dict = EncoderDictionary::new(b"common words, common phrases", 3)?;
let mut c = Compressor::with_prepared_dictionary(&dict);
let compressed = c.compress(b"common phrases, common words")?;

let mut d = zstd_native::Decompressor::with_dictionary(zstd_native::Dictionary::new(
    b"common words, common phrases",
)?);
assert_eq!(d.decompress(&compressed)?, b"common phrases, common words");

Implementations§

Source§

impl EncoderDictionary

Source

pub fn new(dict: &[u8], level: i32) -> Result<EncoderDictionary, Error>

Prepares dict for compression at level (see compress; 0 means the default, 3).

§Errors

Error::InvalidDictionary if a zstd-format dictionary is corrupt.

Source

pub fn id(&self) -> u32

The dictionary ID written in the frames (0 for raw content: none).

Source

pub fn level(&self) -> i32

The level frames compressed with it take.

Trait Implementations§

Source§

impl Clone for EncoderDictionary

Source§

fn clone(&self) -> Self

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 EncoderDictionary

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for EncoderDictionary

§

impl Freeze for EncoderDictionary
where *const ArcInner<CDict> is !null: Freeze, PhantomData<ArcInner<CDict>>: Freeze,

§

impl Move for EncoderDictionary

§

impl RefUnwindSafe for EncoderDictionary

§

impl Send for EncoderDictionary
where Arc<CDict>: Send,

§

impl Sync for EncoderDictionary
where Arc<CDict>: Sync,

§

impl Unpin for EncoderDictionary
where Arc<CDict>: Unpin,

§

impl UnsafeUnpin for EncoderDictionary
where *const ArcInner<CDict> is !null: UnsafeUnpin, PhantomData<ArcInner<CDict>>: UnsafeUnpin,

§

impl UnwindSafe for EncoderDictionary
where Arc<CDict>: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.