Path: blob/main/crates/polars-arrow/src/scalar/fixed_size_binary.rs
8415 views
use super::Scalar;1use crate::datatypes::ArrowDataType;23#[derive(Debug, Clone, PartialEq, Eq)]4/// The [`Scalar`] implementation of fixed size binary ([`Option<Box<[u8]>>`]).5pub struct FixedSizeBinaryScalar {6value: Option<Box<[u8]>>,7dtype: ArrowDataType,8}910impl FixedSizeBinaryScalar {11/// Returns a new [`FixedSizeBinaryScalar`].12/// # Panics13/// iff14/// * the `dtype` is not `FixedSizeBinary`15/// * the size of child binary is not equal16#[inline]17pub fn new<P: Into<Vec<u8>>>(dtype: ArrowDataType, value: Option<P>) -> Self {18assert_eq!(19dtype.to_physical_type(),20crate::datatypes::PhysicalType::FixedSizeBinary21);22Self {23value: value.map(|x| {24let x: Vec<u8> = x.into();25assert_eq!(dtype.to_storage(), &ArrowDataType::FixedSizeBinary(x.len()));26x.into_boxed_slice()27}),28dtype,29}30}3132/// Its value33#[inline]34pub fn value(&self) -> Option<&[u8]> {35self.value.as_ref().map(|x| x.as_ref())36}37}3839impl Scalar for FixedSizeBinaryScalar {40#[inline]41fn as_any(&self) -> &dyn std::any::Any {42self43}4445#[inline]46fn is_valid(&self) -> bool {47self.value.is_some()48}4950#[inline]51fn dtype(&self) -> &ArrowDataType {52&self.dtype53}54}555657