Path: blob/main/crates/polars-arrow/src/scalar/struct_.rs
6939 views
use super::Scalar;1use crate::datatypes::ArrowDataType;23/// A single entry of a [`crate::array::StructArray`].4#[derive(Debug, Clone)]5pub struct StructScalar {6values: Vec<Box<dyn Scalar>>,7is_valid: bool,8dtype: ArrowDataType,9}1011impl PartialEq for StructScalar {12fn eq(&self, other: &Self) -> bool {13(self.dtype == other.dtype)14&& (self.is_valid == other.is_valid)15&& ((!self.is_valid) | (self.values == other.values))16}17}1819impl StructScalar {20/// Returns a new [`StructScalar`]21#[inline]22pub fn new(dtype: ArrowDataType, values: Option<Vec<Box<dyn Scalar>>>) -> Self {23let is_valid = values.is_some();24Self {25values: values.unwrap_or_default(),26is_valid,27dtype,28}29}3031/// Returns the values irrespectively of the validity.32#[inline]33pub fn values(&self) -> &[Box<dyn Scalar>] {34&self.values35}36}3738impl Scalar for StructScalar {39#[inline]40fn as_any(&self) -> &dyn std::any::Any {41self42}4344#[inline]45fn is_valid(&self) -> bool {46self.is_valid47}4849#[inline]50fn dtype(&self) -> &ArrowDataType {51&self.dtype52}53}545556