polars_arrow/scalar/
fixed_size_binary.rs1use super::Scalar;
2use crate::datatypes::ArrowDataType;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct FixedSizeBinaryScalar {
7 value: Option<Box<[u8]>>,
8 dtype: ArrowDataType,
9}
10
11impl FixedSizeBinaryScalar {
12 #[inline]
18 pub fn new<P: Into<Vec<u8>>>(dtype: ArrowDataType, value: Option<P>) -> Self {
19 assert_eq!(
20 dtype.to_physical_type(),
21 crate::datatypes::PhysicalType::FixedSizeBinary
22 );
23 Self {
24 value: value.map(|x| {
25 let x: Vec<u8> = x.into();
26 assert_eq!(
27 dtype.to_logical_type(),
28 &ArrowDataType::FixedSizeBinary(x.len())
29 );
30 x.into_boxed_slice()
31 }),
32 dtype,
33 }
34 }
35
36 #[inline]
38 pub fn value(&self) -> Option<&[u8]> {
39 self.value.as_ref().map(|x| x.as_ref())
40 }
41}
42
43impl Scalar for FixedSizeBinaryScalar {
44 #[inline]
45 fn as_any(&self) -> &dyn std::any::Any {
46 self
47 }
48
49 #[inline]
50 fn is_valid(&self) -> bool {
51 self.value.is_some()
52 }
53
54 #[inline]
55 fn dtype(&self) -> &ArrowDataType {
56 &self.dtype
57 }
58}