Struct VariantObject

Source
pub struct VariantObject<'m, 'v> {
    pub metadata: VariantMetadata<'m>,
    pub value: &'v [u8],
    header: VariantObjectHeader,
    num_elements: u32,
    first_field_offset_byte: u32,
    first_value_byte: u32,
    validated: bool,
}
Expand description

A Variant Object (struct with named fields).

See the Variant spec file for more information.

§Validation

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

Instances produced by Self::try_new or Self::with_full_validation are fully (and recursively) 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. They 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) field accesses against a large object.

A validated instance guarantees that:

  • header byte is valid
  • num_elements is in bounds
  • field id array is in bounds
  • field offset array is in bounds
  • field value array is in bounds
  • all field ids are valid metadata dictionary entries (*)
  • field ids are lexically ordered according by their corresponding string values (*)
  • all field offsets are in bounds (*)
  • all field values are (recursively) valid variant values (*)
  • the associated variant metadata is valid (*)

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 object 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§

§metadata: VariantMetadata<'m>§value: &'v [u8]§header: VariantObjectHeader§num_elements: u32§first_field_offset_byte: u32§first_value_byte: u32§validated: bool

Implementations§

Source§

impl<'m, 'v> VariantObject<'m, 'v>

Source

pub fn new(metadata: VariantMetadata<'m>, value: &'v [u8]) -> Self

Source

pub fn try_new( metadata: VariantMetadata<'m>, value: &'v [u8], ) -> Result<Self, ArrowError>

Attempts to interpet metadata and value as a variant object.

§Validation

This constructor verifies that value points to a valid variant object value. In particular, that all field ids exist in metadata, and all offsets are in-bounds and point to valid objects.

Source

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

Attempts to interpet metadata and value as a variant object, performing only basic (constant-cost) validation.

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 variant object.

Source

pub fn len(&self) -> usize

Returns the number of key-value pairs in this object

Source

pub fn is_empty(&self) -> bool

Returns true if the object contains no key-value pairs

Source

pub fn field(&self, i: usize) -> Option<Variant<'m, 'v>>

Get a field’s value by index in 0..self.len()

§Panics

If the index is out of bounds. Also if variant object is corrupted (e.g., invalid offsets or field IDs). The latter can only happen when working with an unvalidated object produced by Self::new.

Source

pub fn try_field(&self, i: usize) -> Result<Variant<'m, 'v>, ArrowError>

Fallible version of field. Returns field value by index, capturing validation errors

Source

fn try_field_with_shallow_validation( &self, i: usize, ) -> Result<Variant<'m, 'v>, ArrowError>

Source

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

Source

pub fn field_name(&self, i: usize) -> Option<&'m str>

Get a field’s name by index in 0..self.len()

§Panics

If the variant object is corrupted (e.g., invalid offsets or field IDs). This should never happen since the constructor validates all data upfront.

Source

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

Fallible version of field_name. Returns field name by index, capturing validation errors

Source

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

Returns an iterator of (name, value) pairs over the fields of this object.

Source

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

Fallible iteration over the fields of this object.

Source

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

Source

pub fn get(&self, name: &str) -> Option<Variant<'m, 'v>>

Returns the value of the field with the specified name, if any.

Ok(None) means the field does not exist; Err means the search encountered an error.

Trait Implementations§

Source§

impl<'m, 'v> Clone for VariantObject<'m, 'v>

Source§

fn clone(&self) -> VariantObject<'m, 'v>

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, 'v> Debug for VariantObject<'m, 'v>

Source§

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

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

impl<'m, 'v> PartialEq for VariantObject<'m, 'v>

Source§

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

Auto Trait Implementations§

§

impl<'m, 'v> Freeze for VariantObject<'m, 'v>

§

impl<'m, 'v> RefUnwindSafe for VariantObject<'m, 'v>

§

impl<'m, 'v> Send for VariantObject<'m, 'v>

§

impl<'m, 'v> Sync for VariantObject<'m, 'v>

§

impl<'m, 'v> Unpin for VariantObject<'m, 'v>

§

impl<'m, 'v> UnwindSafe for VariantObject<'m, 'v>

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.