vortex_vector/listview/
scalar.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use crate::listview::ListViewVector;
5use crate::{Scalar, ScalarOps, VectorMut, VectorOps};
6
7/// A scalar value for list view types.
8///
9/// The inner value is a ListViewVector with length 1.
10#[derive(Debug)]
11pub struct ListViewScalar(ListViewVector);
12
13impl ListViewScalar {
14    /// Create a new ListViewScalar from a length-1 ListViewVector.
15    ///
16    /// # Panics
17    ///
18    /// Panics if the input vector does not have length 1.
19    pub fn new(vector: ListViewVector) -> Self {
20        assert_eq!(vector.len(), 1);
21        Self(vector)
22    }
23}
24
25impl ScalarOps for ListViewScalar {
26    fn is_valid(&self) -> bool {
27        self.0.validity().value(0)
28    }
29
30    fn repeat(&self, _n: usize) -> VectorMut {
31        todo!()
32    }
33}
34
35impl From<ListViewScalar> for Scalar {
36    fn from(val: ListViewScalar) -> Self {
37        Scalar::List(val)
38    }
39}