Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-arrow/src/scalar/boolean.rs
6939 views
1
use super::Scalar;
2
use crate::datatypes::ArrowDataType;
3
4
/// The [`Scalar`] implementation of a boolean.
5
#[derive(Debug, Clone, PartialEq, Eq)]
6
pub struct BooleanScalar {
7
value: Option<bool>,
8
}
9
10
impl BooleanScalar {
11
/// Returns a new [`BooleanScalar`]
12
#[inline]
13
pub fn new(value: Option<bool>) -> Self {
14
Self { value }
15
}
16
17
/// The value
18
#[inline]
19
pub fn value(&self) -> Option<bool> {
20
self.value
21
}
22
}
23
24
impl Scalar for BooleanScalar {
25
#[inline]
26
fn as_any(&self) -> &dyn std::any::Any {
27
self
28
}
29
30
#[inline]
31
fn is_valid(&self) -> bool {
32
self.value.is_some()
33
}
34
35
#[inline]
36
fn dtype(&self) -> &ArrowDataType {
37
&ArrowDataType::Boolean
38
}
39
}
40
41
impl From<Option<bool>> for BooleanScalar {
42
#[inline]
43
fn from(v: Option<bool>) -> Self {
44
Self::new(v)
45
}
46
}
47
48