Path: blob/main/crates/polars-arrow/src/scalar/binary.rs
6939 views
use super::Scalar;1use crate::datatypes::ArrowDataType;2use crate::offset::Offset;34/// The [`Scalar`] implementation of binary ([`Option<Vec<u8>>`]).5#[derive(Debug, Clone, PartialEq, Eq)]6pub struct BinaryScalar<O: Offset> {7value: Option<Vec<u8>>,8phantom: std::marker::PhantomData<O>,9}1011impl<O: Offset> BinaryScalar<O> {12/// Returns a new [`BinaryScalar`].13#[inline]14pub fn new<P: Into<Vec<u8>>>(value: Option<P>) -> Self {15Self {16value: value.map(|x| x.into()),17phantom: std::marker::PhantomData,18}19}2021/// Its value22#[inline]23pub fn value(&self) -> Option<&[u8]> {24self.value.as_ref().map(|x| x.as_ref())25}26}2728impl<O: Offset, P: Into<Vec<u8>>> From<Option<P>> for BinaryScalar<O> {29#[inline]30fn from(v: Option<P>) -> Self {31Self::new(v)32}33}3435impl<O: Offset> Scalar for BinaryScalar<O> {36#[inline]37fn as_any(&self) -> &dyn std::any::Any {38self39}4041#[inline]42fn is_valid(&self) -> bool {43self.value.is_some()44}4546#[inline]47fn dtype(&self) -> &ArrowDataType {48if O::IS_LARGE {49&ArrowDataType::LargeBinary50} else {51&ArrowDataType::Binary52}53}54}555657