Skip to main content

qubit_value/multi_values/
multi_values_constructor.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10
11//! Internal implementations for constructing `MultiValues` from `Vec<T>`.
12
13/// Internal trait used to create `MultiValues` from `Vec<T>`.
14///
15/// This trait backs `MultiValues::new<T>()`; downstream code should call the
16/// inherent method instead of implementing or naming this trait directly.
17pub trait MultiValuesConstructor<T>: super::sealed::MultiValuesConstructorSealed<T> {
18    /// Builds a `MultiValues` instance from `values`.
19    ///
20    /// # Returns
21    ///
22    /// Returns the enum variant corresponding to `T`.
23    fn from_vec(values: Vec<T>) -> Self;
24}
25
26use std::collections::HashMap;
27use std::time::Duration;
28
29use bigdecimal::BigDecimal;
30use chrono::{
31    DateTime,
32    NaiveDate,
33    NaiveDateTime,
34    NaiveTime,
35    Utc,
36};
37use num_bigint::BigInt;
38use url::Url;
39
40use super::multi_values::MultiValues;
41
42macro_rules! impl_multi_values_constructor {
43    ($type:ty, $variant:ident) => {
44        impl super::sealed::MultiValuesConstructorSealed<$type> for MultiValues {}
45
46        impl MultiValuesConstructor<$type> for MultiValues {
47            #[inline]
48            fn from_vec(values: Vec<$type>) -> Self {
49                MultiValues::$variant(values)
50            }
51        }
52    };
53}
54
55impl_multi_values_constructor!(bool, Bool);
56impl_multi_values_constructor!(char, Char);
57impl_multi_values_constructor!(i8, Int8);
58impl_multi_values_constructor!(i16, Int16);
59impl_multi_values_constructor!(i32, Int32);
60impl_multi_values_constructor!(i64, Int64);
61impl_multi_values_constructor!(i128, Int128);
62impl_multi_values_constructor!(u8, UInt8);
63impl_multi_values_constructor!(u16, UInt16);
64impl_multi_values_constructor!(u32, UInt32);
65impl_multi_values_constructor!(u64, UInt64);
66impl_multi_values_constructor!(u128, UInt128);
67impl_multi_values_constructor!(isize, IntSize);
68impl_multi_values_constructor!(usize, UIntSize);
69impl_multi_values_constructor!(f32, Float32);
70impl_multi_values_constructor!(f64, Float64);
71impl_multi_values_constructor!(String, String);
72impl_multi_values_constructor!(NaiveDate, Date);
73impl_multi_values_constructor!(NaiveTime, Time);
74impl_multi_values_constructor!(NaiveDateTime, DateTime);
75impl_multi_values_constructor!(DateTime<Utc>, Instant);
76impl_multi_values_constructor!(BigInt, BigInteger);
77impl_multi_values_constructor!(BigDecimal, BigDecimal);
78impl_multi_values_constructor!(Duration, Duration);
79impl_multi_values_constructor!(Url, Url);
80impl_multi_values_constructor!(HashMap<String, String>, StringMap);
81impl_multi_values_constructor!(serde_json::Value, Json);