qubit-value 0.13.0

Type-safe containers for single, multi-valued, and named runtime values
Documentation
// =============================================================================
//    Copyright (c) 2025 - 2026 Haixing Hu.
//
//    SPDX-License-Identifier: Apache-2.0
//
//    Licensed under the Apache License, Version 2.0.
// =============================================================================

//! Borrowed semantic views for [`crate::Value`].

use qubit_datatype::DataType;

/// Generates semantic views from the same closed table as owned storage.
macro_rules! define_view {
    (; $(([$($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)*)),+ $(,)?) => {
        /// Borrowed semantic view preserving source types without owning payloads.
        ///
        /// The lifetime is that of the source storage; copying this view does
        /// not clone strings, maps, JSON, or other rich payloads.
        ///
        /// # Type Parameters
        ///
        /// - `'a`: lifetime of the source storage borrowed by payload references.
        ///
        /// # Examples
        ///
        /// ```
        /// use qubit_value::Value;
        /// use qubit_value::ValueRef;
        ///
        /// let value = Value::from(42_i32);
        /// let view: ValueRef<'_> = value.view();
        /// assert!(matches!(view, ValueRef::Int32(42)));
        /// ```
        #[must_use]
        #[non_exhaustive]
        #[derive(Debug, Clone, Copy)]
        pub enum ValueRef<'a> {
            /// Unset storage retaining its declared type.
            Unset(#[doc = "Declared source type."] DataType),
            $(
                #[doc = $value_doc]
                $(#[$cfg])*
                $(#[cfg_attr(docsrs, doc($cfg))])*
                $variant(#[doc = "Borrowed or copied source payload."] value_view_payload_type!($variant, $number_projection, 'a, $type)),
            )+
        }

    };
}

for_each_value_type!(define_view);