Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-arrow/src/scalar/struct_.rs
6939 views
1
use super::Scalar;
2
use crate::datatypes::ArrowDataType;
3
4
/// A single entry of a [`crate::array::StructArray`].
5
#[derive(Debug, Clone)]
6
pub struct StructScalar {
7
values: Vec<Box<dyn Scalar>>,
8
is_valid: bool,
9
dtype: ArrowDataType,
10
}
11
12
impl 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
20
impl StructScalar {
21
/// Returns a new [`StructScalar`]
22
#[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
/// Returns the values irrespectively of the validity.
33
#[inline]
34
pub fn values(&self) -> &[Box<dyn Scalar>] {
35
&self.values
36
}
37
}
38
39
impl 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
}
55
56