Struct VariantMetadata

Source
pub struct VariantMetadata<'m> {
    pub(crate) bytes: &'m [u8],
    header: VariantMetadataHeader,
    dictionary_size: u32,
    first_value_byte: u32,
    validated: bool,
}
Expand description

Variant Metadata

See the Variant Spec file for more information

§Validation

Every instance of variant metadata is either valid or invalid. depending on whether the underlying bytes are a valid encoding of variant metadata (see below).

Instances produced by Self::try_new or Self::with_full_validation are fully validated. They always contain valid data, and infallible accesses such as iteration and indexing are panic-free. The validation cost is linear in the number of underlying bytes.

Instances produced by Self::new are unvalidated and so they may contain either valid or invalid data. Infallible accesses such as iteration and indexing will panic if the underlying bytes are invalid, and fallible alternatives such as Self::iter_try and Self::get are provided as panic-free alternatives. Self::with_full_validation can also be used to validate an unvalidated instance, if desired.

Unvalidated instances can be constructed in constant time. This can be useful if the caller knows the underlying bytes were already validated previously, or if the caller intends to perform a small number of (fallible) accesses to a large dictionary.

A validated variant [metadata instance guarantees that:

  • header byte is valid
  • dictionary size is in bounds
  • offset array content is in-bounds
  • first offset is zero
  • last offset is in-bounds
  • all other offsets are in-bounds (*)
  • all offsets are monotonically increasing (*)
  • all values are valid utf-8 (*)

NOTE: Self::new only skips expensive (non-constant cost) validation checks (marked by (*) in the list above); it panics any of the other checks fails.

§Safety

Even an invalid variant metadata instance is still safe to use in the Rust sense. Accessing it with infallible methods may cause panics but will never lead to undefined behavior.

Fields§

§bytes: &'m [u8]§header: VariantMetadataHeader§dictionary_size: u32§first_value_byte: u32§validated: bool

Implementations§

Source§

impl<'m> VariantMetadata<'m>

Source

pub fn try_new(bytes: &'m [u8]) -> Result<Self, ArrowError>

Attempts to interpret bytes as a variant metadata instance, with full validation of all dictionary entries.

Source

pub fn new(bytes: &'m [u8]) -> Self

Interprets bytes as a variant metadata instance, without attempting to validate dictionary entries. Panics if basic sanity checking fails, and subsequent infallible accesses such as indexing and iteration could also panic if the underlying bytes are invalid.

This constructor can be a useful lightweight alternative to Self::try_new if the bytes were already validated previously by other means, or if the caller expects a small number of accesses to a large dictionary (preferring to use a small number of fallible accesses as needed, instead of paying expensive full validation up front).

Source

pub(crate) fn try_new_with_shallow_validation( bytes: &'m [u8], ) -> Result<Self, ArrowError>

Source

pub fn len(&self) -> usize

The number of metadata dictionary entries

Source

pub fn is_empty(&self) -> bool

True if this metadata dictionary contains no entries

Source

pub fn is_fully_validated(&self) -> bool

True if this instance is fully validated for panic-free infallible accesses.

Source

pub fn with_full_validation(self) -> Result<Self, ArrowError>

Performs a full validation of this metadata dictionary and returns the result.

Source

pub fn is_sorted(&self) -> bool

Whether the dictionary keys are sorted and unique

Source

pub const fn dictionary_size(&self) -> usize

Get the dictionary size

Source

pub const fn version(&self) -> u8

The variant protocol version

Source

fn get_offset(&self, i: usize) -> Result<u32, ArrowError>

Gets an offset array entry by index.

This offset is an index into the dictionary, at the boundary between string i-1 and string i. See Self::get to retrieve a specific dictionary entry.

Source

pub fn get(&self, i: usize) -> Result<&'m str, ArrowError>

Attempts to retrieve a dictionary entry by index, failing if out of bounds or if the underlying bytes are invalid.

Source

pub fn iter_try(&self) -> impl Iterator<Item = Result<&'m str, ArrowError>> + '_

Returns an iterator that attempts to visit all dictionary entries, producing Err if the iterator encounters invalid data.

Source

pub fn iter(&self) -> impl Iterator<Item = &'m str> + '_

Iterates over all dictionary entries. When working with unvalidated input, consider Self::iter_try to avoid panics due to invalid data.

Trait Implementations§

Source§

impl<'m> Clone for VariantMetadata<'m>

Source§

fn clone(&self) -> VariantMetadata<'m>

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<'m> Debug for VariantMetadata<'m>

Source§

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

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

impl Index<usize> for VariantMetadata<'_>

Retrieves the ith dictionary entry, panicking if the index is out of bounds. Accessing unvalidated input could also panic if the underlying bytes are invalid.

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &str

Performs the indexing (container[index]) operation. Read more
Source§

impl<'m> PartialEq for VariantMetadata<'m>

Source§

fn eq(&self, other: &VariantMetadata<'m>) -> 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<'m> StructuralPartialEq for VariantMetadata<'m>

Auto Trait Implementations§

§

impl<'m> Freeze for VariantMetadata<'m>

§

impl<'m> RefUnwindSafe for VariantMetadata<'m>

§

impl<'m> Send for VariantMetadata<'m>

§

impl<'m> Sync for VariantMetadata<'m>

§

impl<'m> Unpin for VariantMetadata<'m>

§

impl<'m> UnwindSafe for VariantMetadata<'m>

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