Skip to main content

DictionaryHandle

Struct DictionaryHandle 

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

Shared pre-parsed dictionary handle for repeated decoding.

Uses Arc on targets with atomics and falls back to Rc otherwise.

Implementations§

Source§

impl DictionaryHandle

Source

pub fn from_dictionary(dict: Dictionary) -> Self

Wrap an already-parsed dictionary in a shared handle.

Source

pub fn heap_size(&self) -> usize

Heap bytes the handle keeps alive: the shared allocation the dictionary lives in and the dictionary’s own content and tables. Clones share all of it.

§Examples
use structured_zstd::decoding::{Dictionary, DictionaryHandle};

let handle = DictionaryHandle::from_dictionary(
    Dictionary::from_raw_content(0, vec![7u8; 1024]).unwrap(),
);
assert!(handle.heap_size() > handle.as_dict().heap_bytes());
assert!(handle.heap_size() <= DictionaryHandle::max_heap_size(1024));
Source

pub fn max_heap_size(content_len: usize) -> usize

Most Self::heap_size a handle over a dictionary of content_len bytes can report, serialized header included, for budgeting before the dictionary is parsed.

Source

pub fn exclusive_heap_size<'a, I>(handles: I) -> usize
where I: IntoIterator<Item = &'a DictionaryHandle>, I::IntoIter: Clone,

Heap bytes that handles alone keep alive: each distinct dictionary among them once, and only when no handle outside them shares it. For an owner holding several handles, such as a decoding context that keeps a dictionary attached and its decoder keeps the last frame’s.

§Examples
use structured_zstd::decoding::{Dictionary, DictionaryHandle};

let handle = DictionaryHandle::from_dictionary(
    Dictionary::from_raw_content(0, vec![7u8; 64]).unwrap(),
);
let copy = handle.clone();
// Both handles are in the set: counted once.
assert_eq!(
    DictionaryHandle::exclusive_heap_size([&handle, &copy]),
    handle.heap_size()
);
// `copy` is held elsewhere: nothing is this set's alone.
assert_eq!(DictionaryHandle::exclusive_heap_size([&handle]), 0);
Source

pub fn decode_dict(raw: &[u8]) -> Result<Self, DictionaryDecodeError>

Parse a serialized dictionary and return a reusable shared handle.

With the legacy feature a dictionary in the v0.5 or v0.6 layout is taken too, whole as content with no ID: frames of its format parse its tables from it, as libzstd’s ZSTD_decompress_usingDict does.

Source

pub fn from_serialized_or_raw_content( raw: &[u8], ) -> Result<Self, DictionaryDecodeError>

Load whichever kind of dictionary raw holds, as ZSTD_createDDict does: a serialized dictionary, or raw content. See Dictionary::from_serialized_or_raw_content.

Source

pub fn id(&self) -> u32

Source

pub fn as_dict(&self) -> &Dictionary

Trait Implementations§

Source§

impl AsRef<Dictionary> for DictionaryHandle

Source§

fn as_ref(&self) -> &Dictionary

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for DictionaryHandle

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 From<Dictionary> for DictionaryHandle

Source§

fn from(dict: Dictionary) -> Self

Converts to this type from the input type.

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

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.