Skip to main content

qubit_value/value/
value_constructor.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//! `From<T>` implementations for all supported `Value` input types.
10
11use super::value::Value;
12
13macro_rules! impl_value_from_table {
14    (
15        ;
16        $(
17            (
18                [$($cfg:meta),*],
19                $variant:ident,
20                $type:ty,
21                $data_type:expr,
22                $materialization:ident,
23                $json_class:ident,
24                $number_projection:ident,
25                $value_doc:literal,
26                $multi_doc:literal
27            )
28        ),+ $(,)?
29    ) => {
30        $(
31            $(#[$cfg])*
32            impl From<$type> for Value {
33                #[inline(always)]
34                fn from(value: $type) -> Self {
35                    Value::$variant(value)
36                }
37            }
38        )+
39    };
40}
41
42for_each_value_type!(impl_value_from_table);
43
44impl From<&str> for Value {
45    #[inline]
46    fn from(value: &str) -> Self {
47        Value::String(value.to_string())
48    }
49}