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
13/// Implements owned scalar conversions from the shared value table.
14macro_rules! impl_value_from_table {
15 (
16 ;
17 $(
18 (
19 [$($cfg:meta),*],
20 $variant:ident,
21 $type:ty,
22 $data_type:expr,
23 $materialization:ident,
24 $json_class:ident,
25 $number_projection:ident,
26 $value_doc:literal,
27 $multi_doc:literal
28 $(, $_wire:tt)*
29 )
30 ),+ $(,)?
31 ) => {
32 $(
33 $(#[$cfg])*
34 impl From<$type> for Value {
35 #[inline(always)]
36 fn from(value: $type) -> Self {
37 Value::$variant(value)
38 }
39 }
40 )+
41 };
42}
43
44for_each_value_type!(impl_value_from_table);
45
46impl From<&str> for Value {
47 #[inline]
48 fn from(value: &str) -> Self {
49 Value::String(value.to_string())
50 }
51}