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 nullability) value ([`ScalarValue`]).
9//!
10//! Note that the implementations of `Scalar` are split into several different modules.
11//!
12//! `Scalar` is the single-row counterpart to [`ArrayRef`](crate::ArrayRef): it is logical, not tied
13//! to any physical array encoding. A scalar always carries its [`DType`], and null scalars are
14//! represented by `value == None`.
15
16#[cfg(feature = "arbitrary")]
17pub mod arbitrary;
18
19mod cast;
20mod constructor;
21mod convert;
22mod display;
23mod downcast;
24mod proto;
25mod scalar_impl;
26mod scalar_value;
27mod truncation;
28mod typed_view;
29mod validate;
30
31pub use scalar_value::*;
32pub use truncation::*;
33pub use typed_view::*;
34
35use crate::dtype::DType;
36
37/// A typed scalar value.
38///
39/// Scalars represent a single value with an associated [`DType`]. The value can be null, in which
40/// case the [`value`][Scalar::value] method returns `None`.
41#[derive(Clone, Debug, Eq)]
42pub struct Scalar {
43 /// The type of the scalar.
44 dtype: DType,
45
46 /// The value of the scalar. This is [`None`] if the value is null, otherwise it is [`Some`].
47 ///
48 /// Invariant: If the [`DType`] is non-nullable, then this value _cannot_ be [`None`].
49 value: Option<ScalarValue>,
50}
51
52#[cfg(test)]
53mod tests;