Skip to main content

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;
18mod arrow;
19
20mod cast;
21mod constructor;
22mod convert;
23mod display;
24mod downcast;
25mod proto;
26mod scalar_impl;
27mod scalar_value;
28mod truncation;
29mod typed_view;
30mod validate;
31
32pub use scalar_value::*;
33pub use truncation::*;
34pub use typed_view::*;
35
36use crate::dtype::DType;
37
38/// A typed scalar value.
39///
40/// Scalars represent a single value with an associated [`DType`]. The value can be null, in which
41/// case the [`value`][Scalar::value] method returns `None`.
42#[derive(Clone, Debug, Eq)]
43pub struct Scalar {
44    /// The type of the scalar.
45    dtype: DType,
46
47    /// The value of the scalar. This is [`None`] if the value is null, otherwise it is [`Some`].
48    ///
49    /// Invariant: If the [`DType`] is non-nullable, then this value _cannot_ be [`None`].
50    value: Option<ScalarValue>,
51}
52
53#[cfg(test)]
54mod tests;