Enum Variant

Source
pub enum Variant<'m, 'v> {
Show 20 variants Null, Int8(i8), Int16(i16), Int32(i32), Int64(i64), Date(NaiveDate), TimestampMicros(DateTime<Utc>), TimestampNtzMicros(NaiveDateTime), Decimal4 { integer: i32, scale: u8, }, Decimal8 { integer: i64, scale: u8, }, Decimal16 { integer: i128, scale: u8, }, Float(f32), Double(f64), BooleanTrue, BooleanFalse, Binary(&'v [u8]), String(&'v str), ShortString(&'v str), Object(VariantObject<'m, 'v>), Array(VariantArray<'m, 'v>),
}
Expand description

Variant value. May contain references to metadata and value

Variants§

§

Null

§

Int8(i8)

§

Int16(i16)

§

Int32(i32)

§

Int64(i64)

§

Date(NaiveDate)

§

TimestampMicros(DateTime<Utc>)

§

TimestampNtzMicros(NaiveDateTime)

§

Decimal4

Fields

§integer: i32
§scale: u8
§

Decimal8

Fields

§integer: i64
§scale: u8
§

Decimal16

Fields

§integer: i128
§scale: u8
§

Float(f32)

§

Double(f64)

§

BooleanTrue

§

BooleanFalse

§

Binary(&'v [u8])

§

String(&'v str)

§

ShortString(&'v str)

§

Object(VariantObject<'m, 'v>)

§

Array(VariantArray<'m, 'v>)

Implementations§

Source§

impl<'m, 'v> Variant<'m, 'v>

Source

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

Parse the buffers and return the appropriate variant.

Source

pub fn as_null(&self) -> Option<()>

Converts this variant to () if it is null.

Returns Some(()) for null variants, None for non-null variants.

§Examples
use parquet_variant::Variant;

// you can extract `()` from a null variant
let v1 = Variant::from(());
assert_eq!(v1.as_null(), Some(()));

// but not from other variants
let v2 = Variant::from("hello!");
assert_eq!(v2.as_null(), None);
Source

pub fn as_boolean(&self) -> Option<bool>

Converts this variant to a bool if possible.

Returns Some(bool) for boolean variants, None for non-boolean variants.

§Examples
use parquet_variant::Variant;

// you can extract a bool from the true variant
let v1 = Variant::from(true);
assert_eq!(v1.as_boolean(), Some(true));

// and the false variant
let v2 = Variant::from(false);
assert_eq!(v2.as_boolean(), Some(false));

// but not from other variants
let v3 = Variant::from("hello!");
assert_eq!(v3.as_boolean(), None);
Source

pub fn as_naive_date(&self) -> Option<NaiveDate>

Converts this variant to a NaiveDate if possible.

Returns Some(NaiveDate) for date variants, None for non-date variants.

§Examples
use parquet_variant::Variant;
use chrono::NaiveDate;

// you can extract a NaiveDate from a date variant
let date = NaiveDate::from_ymd_opt(2025, 4, 12).unwrap();
let v1 = Variant::from(date);
assert_eq!(v1.as_naive_date(), Some(date));

// but not from other variants
let v2 = Variant::from("hello!");
assert_eq!(v2.as_naive_date(), None);
Source

pub fn as_datetime_utc(&self) -> Option<DateTime<Utc>>

Converts this variant to a DateTime<Utc> if possible.

Returns Some(DateTime<Utc>) for timestamp variants, None for non-timestamp variants.

§Examples
use parquet_variant::Variant;
use chrono::NaiveDate;

// you can extract a DateTime<Utc> from a UTC-adjusted variant
let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_milli_opt(12, 34, 56, 780).unwrap().and_utc();
let v1 = Variant::from(datetime);
assert_eq!(v1.as_datetime_utc(), Some(datetime));

// or a non-UTC-adjusted variant
let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_milli_opt(12, 34, 56, 780).unwrap();
let v2 = Variant::from(datetime);
assert_eq!(v2.as_datetime_utc(), Some(datetime.and_utc()));

// but not from other variants
let v3 = Variant::from("hello!");
assert_eq!(v3.as_datetime_utc(), None);
Source

pub fn as_naive_datetime(&self) -> Option<NaiveDateTime>

Converts this variant to a NaiveDateTime if possible.

Returns Some(NaiveDateTime) for timestamp variants, None for non-timestamp variants.

§Examples
use parquet_variant::Variant;
use chrono::NaiveDate;

// you can extract a NaiveDateTime from a non-UTC-adjusted variant
let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_milli_opt(12, 34, 56, 780).unwrap();
let v1 = Variant::from(datetime);
assert_eq!(v1.as_naive_datetime(), Some(datetime));

// or a UTC-adjusted variant
let datetime = NaiveDate::from_ymd_opt(2025, 4, 16).unwrap().and_hms_milli_opt(12, 34, 56, 780).unwrap().and_utc();
let v2 = Variant::from(datetime);
assert_eq!(v2.as_naive_datetime(), Some(datetime.naive_utc()));

// but not from other variants
let v3 = Variant::from("hello!");
assert_eq!(v3.as_naive_datetime(), None);
Source

pub fn as_u8_slice(&'v self) -> Option<&'v [u8]>

Converts this variant to a &[u8] if possible.

Returns Some(&[u8]) for binary variants, None for non-binary variants.

§Examples
use parquet_variant::Variant;

// you can extract a byte slice from a binary variant
let data = b"hello!";
let v1 = Variant::Binary(data);
assert_eq!(v1.as_u8_slice(), Some(data.as_slice()));

// but not from other variant types
let v2 = Variant::from(123i64);
assert_eq!(v2.as_u8_slice(), None);
Source

pub fn as_string(&'v self) -> Option<&'v str>

Converts this variant to a &str if possible.

Returns Some(&str) for string variants (both regular and short strings), None for non-string variants.

§Examples
use parquet_variant::Variant;

// you can extract a string from string variants
let s = "hello!";
let v1 = Variant::ShortString(s);
assert_eq!(v1.as_string(), Some(s));

// but not from other variants
let v2 = Variant::from(123i64);
assert_eq!(v2.as_string(), None);
Source

pub fn as_int8(&self) -> Option<i8>

Converts this variant to an i8 if possible.

Returns Some(i8) for integer variants that fit in i8 range, None for non-integer variants or values that would overflow.

§Examples
use parquet_variant::Variant;

// you can read an int64 variant into an i8 if it fits
let v1 = Variant::from(123i64);
assert_eq!(v1.as_int8(), Some(123i8));

// but not if it would overflow
let v2 = Variant::from(1234i64);
assert_eq!(v2.as_int8(), None);

// or if the variant cannot be cast into an integer
let v3 = Variant::from("hello!");
assert_eq!(v3.as_int8(), None);
Source

pub fn as_int16(&self) -> Option<i16>

Converts this variant to an i16 if possible.

Returns Some(i16) for integer variants that fit in i16 range, None for non-integer variants or values that would overflow.

§Examples
use parquet_variant::Variant;

// you can read an int64 variant into an i16 if it fits
let v1 = Variant::from(123i64);
assert_eq!(v1.as_int16(), Some(123i16));

// but not if it would overflow
let v2 = Variant::from(123456i64);
assert_eq!(v2.as_int16(), None);

// or if the variant cannot be cast into an integer
let v3 = Variant::from("hello!");
assert_eq!(v3.as_int16(), None);
Source

pub fn as_int32(&self) -> Option<i32>

Converts this variant to an i32 if possible.

Returns Some(i32) for integer variants that fit in i32 range, None for non-integer variants or values that would overflow.

§Examples
use parquet_variant::Variant;

// you can read an int64 variant into an i32 if it fits
let v1 = Variant::from(123i64);
assert_eq!(v1.as_int32(), Some(123i32));

// but not if it would overflow
let v2 = Variant::from(12345678901i64);
assert_eq!(v2.as_int32(), None);

// or if the variant cannot be cast into an integer
let v3 = Variant::from("hello!");
assert_eq!(v3.as_int32(), None);
Source

pub fn as_int64(&self) -> Option<i64>

Converts this variant to an i64 if possible.

Returns Some(i64) for integer variants that fit in i64 range, None for non-integer variants or values that would overflow.

§Examples
use parquet_variant::Variant;

// you can read an int64 variant into an i64
let v1 = Variant::from(123i64);
assert_eq!(v1.as_int64(), Some(123i64));

// but not a variant that cannot be cast into an integer
let v2 = Variant::from("hello!");
assert_eq!(v2.as_int64(), None);
Source

pub fn as_decimal_int32(&self) -> Option<(i32, u8)>

Converts this variant to tuple with a 4-byte unscaled value if possible.

Returns Some((i32, u8)) for decimal variants where the unscaled value fits in i32 range, None for non-decimal variants or decimal values that would overflow.

§Examples
use parquet_variant::Variant;

// you can extract decimal parts from smaller or equally-sized decimal variants
let v1 = Variant::from((1234_i32, 2));
assert_eq!(v1.as_decimal_int32(), Some((1234_i32, 2)));

// and from larger decimal variants if they fit
let v2 = Variant::from((1234_i64, 2));
assert_eq!(v2.as_decimal_int32(), Some((1234_i32, 2)));

// but not if the value would overflow i32
let v3 = Variant::from((12345678901i64, 2));
assert_eq!(v3.as_decimal_int32(), None);

// or if the variant is not a decimal
let v4 = Variant::from("hello!");
assert_eq!(v4.as_decimal_int32(), None);
Source

pub fn as_decimal_int64(&self) -> Option<(i64, u8)>

Converts this variant to tuple with an 8-byte unscaled value if possible.

Returns Some((i64, u8)) for decimal variants where the unscaled value fits in i64 range, None for non-decimal variants or decimal values that would overflow.

§Examples
use parquet_variant::Variant;

// you can extract decimal parts from smaller or equally-sized decimal variants
let v1 = Variant::from((1234_i64, 2));
assert_eq!(v1.as_decimal_int64(), Some((1234_i64, 2)));

// and from larger decimal variants if they fit
let v2 = Variant::from((1234_i128, 2));
assert_eq!(v2.as_decimal_int64(), Some((1234_i64, 2)));

// but not if the value would overflow i64
let v3 = Variant::from((2e19 as i128, 2));
assert_eq!(v3.as_decimal_int64(), None);

// or if the variant is not a decimal
let v4 = Variant::from("hello!");
assert_eq!(v4.as_decimal_int64(), None);
Source

pub fn as_decimal_int128(&self) -> Option<(i128, u8)>

Converts this variant to tuple with a 16-byte unscaled value if possible.

Returns Some((i128, u8)) for decimal variants where the unscaled value fits in i128 range, None for non-decimal variants or decimal values that would overflow.

§Examples
use parquet_variant::Variant;

// you can extract decimal parts from smaller or equally-sized decimal variants
let v1 = Variant::from((1234_i128, 2));
assert_eq!(v1.as_decimal_int128(), Some((1234_i128, 2)));

// but not if the variant is not a decimal
let v2 = Variant::from("hello!");
assert_eq!(v2.as_decimal_int128(), None);
Source

pub fn as_f32(&self) -> Option<f32>

Converts this variant to an f32 if possible.

Returns Some(f32) for float and double variants, None for non-floating-point variants.

§Examples
use parquet_variant::Variant;

// you can extract an f32 from a float variant
let v1 = Variant::from(std::f32::consts::PI);
assert_eq!(v1.as_f32(), Some(std::f32::consts::PI));

// and from a double variant (with loss of precision to nearest f32)
let v2 = Variant::from(std::f64::consts::PI);
assert_eq!(v2.as_f32(), Some(std::f32::consts::PI));

// but not from other variants
let v3 = Variant::from("hello!");
assert_eq!(v3.as_f32(), None);
Source

pub fn as_f64(&self) -> Option<f64>

Converts this variant to an f64 if possible.

Returns Some(f64) for float and double variants, None for non-floating-point variants.

§Examples
use parquet_variant::Variant;

// you can extract an f64 from a float variant
let v1 = Variant::from(std::f32::consts::PI);
assert_eq!(v1.as_f64(), Some(std::f32::consts::PI as f64));

// and from a double variant
let v2 = Variant::from(std::f64::consts::PI);
assert_eq!(v2.as_f64(), Some(std::f64::consts::PI));

// but not from other variants
let v3 = Variant::from("hello!");
assert_eq!(v3.as_f64(), None);
Source

pub fn metadata(&self) -> Option<&'m VariantMetadata<'_>>

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Variant<'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 Variant<'m, 'v>

Source§

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

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

impl<'v> From<&'v [u8]> for Variant<'_, 'v>

Source§

fn from(value: &'v [u8]) -> Self

Converts to this type from the input type.
Source§

impl<'v> From<&'v str> for Variant<'_, 'v>

Source§

fn from(value: &'v str) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Variant<'_, '_>

Source§

fn from((): ()) -> Self

Converts to this type from the input type.
Source§

impl From<(i128, u8)> for Variant<'_, '_>

Source§

fn from(value: (i128, u8)) -> Self

Converts to this type from the input type.
Source§

impl From<(i32, u8)> for Variant<'_, '_>

Source§

fn from(value: (i32, u8)) -> Self

Converts to this type from the input type.
Source§

impl From<(i64, u8)> for Variant<'_, '_>

Source§

fn from(value: (i64, u8)) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime<Utc>> for Variant<'_, '_>

Source§

fn from(value: DateTime<Utc>) -> Self

Converts to this type from the input type.
Source§

impl From<NaiveDate> for Variant<'_, '_>

Source§

fn from(value: NaiveDate) -> Self

Converts to this type from the input type.
Source§

impl From<NaiveDateTime> for Variant<'_, '_>

Source§

fn from(value: NaiveDateTime) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Variant<'_, '_>

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Variant<'_, '_>

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Variant<'_, '_>

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Variant<'_, '_>

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Variant<'_, '_>

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Variant<'_, '_>

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Variant<'_, '_>

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Source§

impl<'m, 'v> StructuralPartialEq for Variant<'m, 'v>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'m, 'v> UnwindSafe for Variant<'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.