Skip to main content

lichtung_plot/data/
payload.rs

1//! Readback of actual owning scientific declarations.
2
3use std::sync::Arc;
4
5use super::{
6    ArrayValues, AxisValues, DateValues, DurationValues, EstimateStatus, IntegerValues, KeyColumns,
7    RawKeyValues, TimeValues, VariableValues,
8};
9use crate::{
10    plots::{HistogramGeometry, HistogramKde, RaincloudGeometry},
11    scales::AlphaEncoding,
12    BooleanValues, CategoryValues, NumericValues,
13};
14
15macro_rules! payloads {
16    ($($variant:ident($ty:ty) => $name:literal),+ $(,)?) => {
17        /// Owned original values as supplied to the native declaration.
18        #[derive(Debug, Clone)]
19        #[non_exhaustive]
20        #[expect(clippy::large_enum_variant, reason = "own the exact public native payload types through the shared DataValue snapshot")]
21        pub enum DataPayload {
22            $(#[doc = concat!("Actual ", $name, " values.")] $variant($ty),)+
23        }
24
25        /// Discriminant of the actual native payload, independent of its role.
26        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
27        #[non_exhaustive]
28        pub enum DataValueType {
29            $(#[doc = concat!("Actual ", $name, " payload.")] $variant,)+
30        }
31
32        impl DataPayload {
33            /// The actual payload type.
34            pub const fn value_type(&self) -> DataValueType {
35                match self {
36                    $(Self::$variant(_) => DataValueType::$variant,)+
37                }
38            }
39        }
40
41        impl DataValueType {
42            /// Canonical spelling for typed language bindings.
43            #[doc(hidden)]
44            pub const fn as_str(self) -> &'static str {
45                match self {
46                    $(Self::$variant => $name,)+
47                }
48            }
49        }
50    };
51}
52
53payloads!(
54    Numeric(NumericValues) => "numeric",
55    Category(CategoryValues) => "category",
56    RawKeys(RawKeyValues) => "raw_keys",
57    Boolean(BooleanValues) => "boolean",
58    Integer(IntegerValues) => "integer",
59    Date(DateValues) => "date",
60    Instant(TimeValues) => "instant",
61    Duration(DurationValues) => "duration",
62    Axis(AxisValues) => "axis",
63    Array(ArrayValues) => "array",
64    EstimateStatuses(Arc<[EstimateStatus]>) => "estimate_statuses",
65    HistogramKde(HistogramKde) => "histogram_kde",
66    HistogramGeometry(HistogramGeometry) => "histogram_geometry",
67    RaincloudGeometry(RaincloudGeometry) => "raincloud_geometry",
68    Variables(VariableValues) => "variables",
69    KeyColumns(KeyColumns) => "key_columns",
70    AlphaEncoding(AlphaEncoding) => "alpha_encoding",
71);