vortex_array/scalar/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Scalar values and types for the Vortex system.
5//!
6//! This crate provides scalar types and values that can be used to represent individual data
7//! elements in the Vortex array system. [`Scalar`]s are composed of a logical data type ([`DType`])
8//! and an optional (encoding nullablity) value ([`ScalarValue`]).
9//!
10//! Note that the implementations of `Scalar` are split into several different modules.
11
12#[cfg(feature = "arbitrary")]
13pub mod arbitrary;
14mod arrow;
15
16mod cast;
17mod constructor;
18mod convert;
19mod display;
20mod downcast;
21mod proto;
22
23use vortex_dtype::DType;
24
25/// A typed scalar value.
26///
27/// Scalars represent a single value with an associated [`DType`]. The value can be null, in which
28/// case the [`value`][Scalar::value] method returns `None`.
29#[derive(Clone, Debug, Eq)]
30pub struct Scalar {
31 /// The type of the scalar.
32 dtype: DType,
33
34 /// The value of the scalar. This is [`None`] if the value is null, otherwise it is [`Some`].
35 ///
36 /// Invariant: If the [`DType`] is non-nullable, then this value _cannot_ be [`None`].
37 value: Option<ScalarValue>,
38}
39
40mod scalar_impl;
41mod scalar_value;
42mod typed_view;
43
44pub use scalar_value::*;
45pub use typed_view::*;
46
47#[cfg(test)]
48mod tests;
49mod truncation;
50
51pub use truncation::*;