Skip to main content

qubit_value/value/
value_ref.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8
9//! Borrowed semantic views for [`crate::Value`].
10
11use qubit_datatype::DataType;
12
13/// Generates semantic views from the same closed table as owned storage.
14macro_rules! define_view {
15    (; $(([$($cfg:meta),*], $variant:ident, $type:ty, $data_type:expr, $materialization:ident, $json_class:ident, $number_projection:ident, $value_doc:literal, $multi_doc:literal $(, $_wire:tt)*)),+ $(,)?) => {
16        /// Borrowed semantic view preserving source types without owning payloads.
17        ///
18        /// The lifetime is that of the source storage; copying this view does
19        /// not clone strings, maps, JSON, or other rich payloads.
20        #[must_use]
21        #[non_exhaustive]
22        #[derive(Debug, Clone, Copy)]
23        pub enum ValueRef<'a> {
24            /// Unset storage retaining its declared type.
25            Unset(#[doc = "Declared source type."] DataType),
26            $(
27                $(#[$cfg])*
28                #[doc = $value_doc]
29                $variant(#[doc = "Borrowed or copied source payload."] value_view_payload_type!($variant, $number_projection, 'a, $type)),
30            )+
31        }
32
33    };
34}
35
36for_each_value_type!(define_view);