Path: blob/main/crates/polars-arrow/src/scalar/fixed_size_binary.rs
6939 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!(26dtype.to_logical_type(),27&ArrowDataType::FixedSizeBinary(x.len())28);29x.into_boxed_slice()30}),31dtype,32}33}3435/// Its value36#[inline]37pub fn value(&self) -> Option<&[u8]> {38self.value.as_ref().map(|x| x.as_ref())39}40}4142impl Scalar for FixedSizeBinaryScalar {43#[inline]44fn as_any(&self) -> &dyn std::any::Any {45self46}4748#[inline]49fn is_valid(&self) -> bool {50self.value.is_some()51}5253#[inline]54fn dtype(&self) -> &ArrowDataType {55&self.dtype56}57}585960