polars_arrow/scalar/
struct_.rs1use super::Scalar;
2use crate::datatypes::ArrowDataType;
3
4#[derive(Debug, Clone)]
6pub struct StructScalar {
7 values: Vec<Box<dyn Scalar>>,
8 is_valid: bool,
9 dtype: ArrowDataType,
10}
11
12impl PartialEq for StructScalar {
13 fn eq(&self, other: &Self) -> bool {
14 (self.dtype == other.dtype)
15 && (self.is_valid == other.is_valid)
16 && ((!self.is_valid) | (self.values == other.values))
17 }
18}
19
20impl StructScalar {
21 #[inline]
23 pub fn new(dtype: ArrowDataType, values: Option<Vec<Box<dyn Scalar>>>) -> Self {
24 let is_valid = values.is_some();
25 Self {
26 values: values.unwrap_or_default(),
27 is_valid,
28 dtype,
29 }
30 }
31
32 #[inline]
34 pub fn values(&self) -> &[Box<dyn Scalar>] {
35 &self.values
36 }
37}
38
39impl Scalar for StructScalar {
40 #[inline]
41 fn as_any(&self) -> &dyn std::any::Any {
42 self
43 }
44
45 #[inline]
46 fn is_valid(&self) -> bool {
47 self.is_valid
48 }
49
50 #[inline]
51 fn dtype(&self) -> &ArrowDataType {
52 &self.dtype
53 }
54}