Skip to main content

qubit_value/
multi_values.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026.
4 *    Haixing Hu, Qubit Co. Ltd.
5 *
6 *    All rights reserved.
7 *
8 ******************************************************************************/
9//! # Multiple Values Container
10//!
11//! Provides type-safe storage and access functionality for multiple values.
12//!
13//! # Author
14//!
15//! Haixing Hu
16
17#![allow(private_bounds)]
18
19use bigdecimal::BigDecimal;
20use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
21use num_bigint::BigInt;
22use serde::{Deserialize, Serialize};
23use std::collections::HashMap;
24use std::time::Duration;
25use url::Url;
26
27use qubit_common::lang::DataType;
28
29use super::error::{ValueError, ValueResult};
30use super::value::Value;
31
32/// Multiple values container
33///
34/// Uses an enum to represent multiple values of different types, providing
35/// type-safe storage and access for multiple values.
36///
37/// # Features
38///
39/// - Supports collections of multiple basic data types.
40/// - Provides two sets of APIs for type checking and type conversion.
41/// - Supports unified access to single and multiple values.
42/// - Automatic memory management.
43///
44/// # Example
45///
46/// ```rust
47/// use qubit_value::MultiValues;
48///
49/// // Create integer multiple values
50/// let mut values = MultiValues::Int32(vec![1, 2, 3]);
51/// assert_eq!(values.count(), 3);
52/// assert_eq!(values.get_first_int32().unwrap(), 1);
53///
54/// // Get all values
55/// let all = values.get_int32s().unwrap();
56/// assert_eq!(all, &[1, 2, 3]);
57///
58/// // Use generic method to add value
59/// values.add(4).unwrap();
60/// assert_eq!(values.count(), 4);
61/// ```
62///
63/// # Author
64///
65/// Haixing Hu
66///
67#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
68pub enum MultiValues {
69    /// Empty value (has type but no values)
70    Empty(DataType),
71    /// Boolean value list
72    Bool(Vec<bool>),
73    /// Character value list
74    Char(Vec<char>),
75    /// i8 list
76    Int8(Vec<i8>),
77    /// i16 list
78    Int16(Vec<i16>),
79    /// i32 list
80    Int32(Vec<i32>),
81    /// i64 list
82    Int64(Vec<i64>),
83    /// i128 list
84    Int128(Vec<i128>),
85    /// u8 list
86    UInt8(Vec<u8>),
87    /// u16 list
88    UInt16(Vec<u16>),
89    /// u32 list
90    UInt32(Vec<u32>),
91    /// u64 list
92    UInt64(Vec<u64>),
93    /// u128 list
94    UInt128(Vec<u128>),
95    /// isize list
96    IntSize(Vec<isize>),
97    /// usize list
98    UIntSize(Vec<usize>),
99    /// f32 list
100    Float32(Vec<f32>),
101    /// f64 list
102    Float64(Vec<f64>),
103    /// Big integer list
104    BigInteger(Vec<BigInt>),
105    /// Big decimal list
106    BigDecimal(Vec<BigDecimal>),
107    /// String list
108    String(Vec<String>),
109    /// Date list
110    Date(Vec<NaiveDate>),
111    /// Time list
112    Time(Vec<NaiveTime>),
113    /// DateTime list
114    DateTime(Vec<NaiveDateTime>),
115    /// UTC instant list
116    Instant(Vec<DateTime<Utc>>),
117    /// Duration list
118    Duration(Vec<Duration>),
119    /// Url list
120    Url(Vec<Url>),
121    /// StringMap list
122    StringMap(Vec<HashMap<String, String>>),
123    /// Json list
124    Json(Vec<serde_json::Value>),
125}
126
127// ============================================================================
128// Getter method generation macros
129// ============================================================================
130
131/// Unified multiple values getter generation macro
132///
133/// Generates `get_[xxx]s` methods for `MultiValues`, returning a reference to
134/// value slices.
135///
136/// # Documentation Comment Support
137///
138/// The macro automatically extracts preceding documentation comments, so you
139/// can add `///` comments before macro invocations.
140///
141/// # Author
142///
143/// Haixing Hu
144///
145macro_rules! impl_get_multi_values {
146    // Simple type: return slice reference
147    ($(#[$attr:meta])* slice: $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
148        $(#[$attr])*
149        #[inline]
150        pub fn $method(&self) -> ValueResult<&[$type]> {
151            match self {
152                MultiValues::$variant(v) => Ok(v),
153                MultiValues::Empty(dt) if *dt == $data_type => Ok(&[]),
154                _ => Err(ValueError::TypeMismatch {
155                    expected: $data_type,
156                    actual: self.data_type(),
157                }),
158            }
159        }
160    };
161
162    // Complex type: return Vec reference (e.g., Vec<String>, Vec<Vec<u8>>)
163    ($(#[$attr:meta])* vec: $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
164        $(#[$attr])*
165        #[inline]
166        pub fn $method(&self) -> ValueResult<&[$type]> {
167            match self {
168                MultiValues::$variant(v) => Ok(v.as_slice()),
169                MultiValues::Empty(dt) if *dt == $data_type => Ok(&[]),
170                _ => Err(ValueError::TypeMismatch {
171                    expected: $data_type,
172                    actual: self.data_type(),
173                }),
174            }
175        }
176    };
177}
178
179/// Unified multiple values get_first method generation macro
180///
181/// Generates `get_first_[xxx]` methods for `MultiValues`, used to get the first
182/// value.
183///
184/// # Documentation Comment Support
185///
186/// The macro automatically extracts preceding documentation comments, so you
187/// can add `///` comments before macro invocations.
188///
189/// # Author
190///
191/// Haixing Hu
192///
193macro_rules! impl_get_first_value {
194    // Copy type: directly return value
195    ($(#[$attr:meta])* copy: $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
196        $(#[$attr])*
197        #[inline]
198        pub fn $method(&self) -> ValueResult<$type> {
199            match self {
200                MultiValues::$variant(v) if !v.is_empty() => Ok(v[0]),
201                MultiValues::$variant(_) => Err(ValueError::NoValue),
202                MultiValues::Empty(dt) if *dt == $data_type => Err(ValueError::NoValue),
203                _ => Err(ValueError::TypeMismatch {
204                    expected: $data_type,
205                    actual: self.data_type(),
206                }),
207            }
208        }
209    };
210
211    // Reference type: return reference
212    ($(#[$attr:meta])* ref: $method:ident, $variant:ident, $ret_type:ty, $data_type:expr, $conversion:expr) => {
213        $(#[$attr])*
214        #[inline]
215        pub fn $method(&self) -> ValueResult<$ret_type> {
216            match self {
217                MultiValues::$variant(v) if !v.is_empty() => {
218                    let conv_fn: fn(&_) -> $ret_type = $conversion;
219                    Ok(conv_fn(&v[0]))
220                },
221                MultiValues::$variant(_) => Err(ValueError::NoValue),
222                MultiValues::Empty(dt) if *dt == $data_type => Err(ValueError::NoValue),
223                _ => Err(ValueError::TypeMismatch {
224                    expected: $data_type,
225                    actual: self.data_type(),
226                }),
227            }
228        }
229    };
230}
231
232/// Unified multiple values add method generation macro
233///
234/// Generates `add_[xxx]` methods for `MultiValues`, used to add a single value.
235///
236/// # Documentation Comment Support
237///
238/// The macro automatically extracts preceding documentation comments, so you
239/// can add `///` comments before macro invocations.
240///
241/// # Author
242///
243/// Haixing Hu
244///
245macro_rules! impl_add_single_value {
246    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
247        $(#[$attr])*
248        #[inline]
249        pub fn $method(&mut self, value: $type) -> ValueResult<()> {
250            match self {
251                MultiValues::$variant(v) => {
252                    v.push(value);
253                    Ok(())
254                }
255                MultiValues::Empty(dt) if *dt == $data_type => {
256                    *self = MultiValues::$variant(vec![value]);
257                    Ok(())
258                }
259                _ => Err(ValueError::TypeMismatch {
260                    expected: $data_type,
261                    actual: self.data_type(),
262                }),
263            }
264        }
265    };
266}
267
268/// Unified multiple values add multiple method generation macro
269///
270/// Generates `add_[xxx]s` methods for `MultiValues`, used to add multiple values.
271///
272/// # Documentation Comment Support
273///
274/// The macro automatically extracts preceding documentation comments, so you
275/// can add `///` comments before macro invocations.
276///
277/// # Author
278///
279/// Haixing Hu
280///
281macro_rules! impl_add_multi_values {
282    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
283        $(#[$attr])*
284        #[inline]
285        pub fn $method(&mut self, values: Vec<$type>) -> ValueResult<()> {
286            match self {
287                MultiValues::$variant(v) => {
288                    v.extend(values);
289                    Ok(())
290                }
291                MultiValues::Empty(dt) if *dt == $data_type => {
292                    *self = MultiValues::$variant(values);
293                    Ok(())
294                }
295                _ => Err(ValueError::TypeMismatch {
296                    expected: $data_type,
297                    actual: self.data_type(),
298                }),
299            }
300        }
301    };
302}
303
304/// Unified multiple values add from slice method generation macro
305///
306/// Generates `add_[xxx]s_slice` methods for `MultiValues`, used to append
307/// multiple values at once from a slice.
308///
309/// # Author
310///
311/// Haixing Hu
312///
313macro_rules! impl_add_multi_values_slice {
314    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
315        $(#[$attr])*
316        #[inline]
317        pub fn $method(&mut self, values: &[$type]) -> ValueResult<()> {
318            match self {
319                MultiValues::$variant(v) => {
320                    v.extend_from_slice(values);
321                    Ok(())
322                }
323                MultiValues::Empty(dt) if *dt == $data_type => {
324                    *self = MultiValues::$variant(values.to_vec());
325                    Ok(())
326                }
327                _ => Err(ValueError::TypeMismatch {
328                    expected: $data_type,
329                    actual: self.data_type(),
330                }),
331            }
332        }
333    };
334}
335
336/// Unified multiple values single value set method generation macro
337///
338/// Generates `set_[xxx]` methods for `MultiValues`, used to set a single value
339/// (replacing the entire list).
340///
341/// # Documentation Comment Support
342///
343/// The macro automatically extracts preceding documentation comments, so you
344/// can add `///` comments before macro invocations.
345///
346/// # Author
347///
348/// Haixing Hu
349///
350macro_rules! impl_set_single_value {
351    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
352        $(#[$attr])*
353        pub fn $method(&mut self, value: $type) -> ValueResult<()> {
354            *self = MultiValues::$variant(vec![value]);
355            Ok(())
356        }
357    };
358}
359
360/// Unified multiple values set method generation macro
361///
362/// Generates `set_[xxx]s` methods for `MultiValues`, used to set the entire
363/// value list.
364///
365/// # Documentation Comment Support
366///
367/// The macro automatically extracts preceding documentation comments, so you
368/// can add `///` comments before macro invocations.
369///
370/// # Author
371///
372/// Haixing Hu
373///
374macro_rules! impl_set_multi_values {
375    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
376        $(#[$attr])*
377        pub fn $method(&mut self, values: Vec<$type>) -> ValueResult<()> {
378            *self = MultiValues::$variant(values);
379            Ok(())
380        }
381    };
382}
383
384/// Unified multiple values set (slice) method generation macro
385///
386/// Generates `set_[xxx]s_slice` methods for `MultiValues`, used to set the
387/// entire value list from a slice.
388///
389/// This method directly replaces the internally stored list without type
390/// matching checks, behaving consistently with `set_[xxx]s`.
391///
392/// # Documentation Comment Support
393///
394/// The macro automatically extracts preceding documentation comments, so you
395/// can add `///` comments before macro invocations.
396///
397/// # Author
398///
399/// Haixing Hu
400///
401macro_rules! impl_set_multi_values_slice {
402    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
403        $(#[$attr])*
404        pub fn $method(&mut self, values: &[$type]) -> ValueResult<()> {
405            *self = MultiValues::$variant(values.to_vec());
406            Ok(())
407        }
408    };
409}
410
411impl MultiValues {
412    /// Generic constructor method
413    ///
414    /// Creates `MultiValues` from `Vec<T>`, avoiding direct use of enum
415    /// variants.
416    ///
417    /// # Type Parameters
418    ///
419    /// * `T` - Element type
420    ///
421    /// # Returns
422    ///
423    /// Returns `MultiValues` wrapping the given value list
424    ///
425    /// # Example
426    ///
427    /// ```rust
428    /// use qubit_value::MultiValues;
429    ///
430    /// // Basic types
431    /// let mv = MultiValues::new(vec![1, 2, 3]);
432    /// assert_eq!(mv.count(), 3);
433    ///
434    /// // Strings
435    /// let mv = MultiValues::new(vec!["a".to_string(), "b".to_string()]);
436    /// assert_eq!(mv.count(), 2);
437    /// ```
438    #[inline]
439    pub fn new<T>(values: Vec<T>) -> Self
440    where
441        Self: MultiValuesConstructor<T>,
442    {
443        <Self as MultiValuesConstructor<T>>::from_vec(values)
444    }
445
446    /// Generic getter method for multiple values
447    ///
448    /// Automatically selects the correct getter method based on the target
449    /// type, performing strict type checking.
450    ///
451    /// # Type Parameters
452    ///
453    /// * `T` - The target element type to retrieve.
454    ///
455    /// # Returns
456    ///
457    /// If types match, returns the list of values; otherwise returns an error.
458    ///
459    /// # Example
460    ///
461    /// ```rust
462    /// use qubit_value::MultiValues;
463    ///
464    /// let multi = MultiValues::Int32(vec![1, 2, 3]);
465    ///
466    /// // Through type inference
467    /// let nums: Vec<i32> = multi.get().unwrap();
468    /// assert_eq!(nums, vec![1, 2, 3]);
469    ///
470    /// // Explicitly specify type parameter
471    /// let nums = multi.get::<i32>().unwrap();
472    /// assert_eq!(nums, vec![1, 2, 3]);
473    /// ```
474    #[inline]
475    pub fn get<T>(&self) -> ValueResult<Vec<T>>
476    where
477        Self: MultiValuesGetter<T>,
478    {
479        <Self as MultiValuesGetter<T>>::get_values(self)
480    }
481
482    /// Generic getter method for the first value
483    ///
484    /// Automatically selects the correct getter method based on the target type,
485    /// performing strict type checking.
486    ///
487    /// # Type Parameters
488    ///
489    /// * `T` - The target element type to retrieve.
490    ///
491    /// # Returns
492    ///
493    /// If types match and a value exists, returns the first value; otherwise
494    /// returns an error.
495    ///
496    /// # Example
497    ///
498    /// ```rust
499    /// use qubit_value::MultiValues;
500    ///
501    /// let multi = MultiValues::Int32(vec![42, 100, 200]);
502    ///
503    /// // Through type inference
504    /// let first: i32 = multi.get_first().unwrap();
505    /// assert_eq!(first, 42);
506    ///
507    /// // Explicitly specify type parameter
508    /// let first = multi.get_first::<i32>().unwrap();
509    /// assert_eq!(first, 42);
510    ///
511    /// // String type
512    /// let multi = MultiValues::String(vec!["hello".to_string(), "world".to_string()]);
513    /// let first: String = multi.get_first().unwrap();
514    /// assert_eq!(first, "hello");
515    /// ```
516    #[inline]
517    pub fn get_first<T>(&self) -> ValueResult<T>
518    where
519        Self: MultiValuesFirstGetter<T>,
520    {
521        <Self as MultiValuesFirstGetter<T>>::get_first_value(self)
522    }
523
524    /// Generic setter method
525    ///
526    /// Automatically selects the optimal setter path based on the input type,
527    /// replacing the entire list.
528    ///
529    /// This operation updates the stored type to the input element type and
530    /// does not validate runtime compatibility with the previous variant.
531    ///
532    /// Supports three input forms, all unified to this method via internal
533    /// dispatch traits:
534    ///
535    /// - `Vec<T>`: Takes `set_values(Vec<T>)` path with zero additional allocation
536    /// - `&[T]`: Takes `set_values_slice(&[T])` path
537    /// - `T`: Takes `set_single_value(T)` path
538    ///
539    /// # Type Parameters
540    ///
541    /// * `S` - Input type, can be `Vec<T>`, `&[T]`, or a single `T`
542    ///
543    /// # Parameters
544    ///
545    /// * `values` - The value collection to set, can be `Vec<T>`, `&[T]`, or a
546    ///   single `T`
547    ///
548    /// # Returns
549    ///
550    /// If setting succeeds, returns `Ok(())`; otherwise returns an error.
551    ///
552    /// # Example
553    ///
554    /// ```rust
555    /// use qubit_common::lang::DataType;
556    /// use qubit_value::MultiValues;
557    ///
558    /// // 1) Vec<T>
559    /// let mut mv = MultiValues::Empty(DataType::Int32);
560    /// mv.set(vec![42, 100, 200]).unwrap();
561    /// assert_eq!(mv.get_int32s().unwrap(), &[42, 100, 200]);
562    ///
563    /// // 2) &[T]
564    /// let mut mv = MultiValues::Empty(DataType::Int32);
565    /// let slice = &[7, 8, 9][..];
566    /// mv.set(slice).unwrap();
567    /// assert_eq!(mv.get_int32s().unwrap(), &[7, 8, 9]);
568    ///
569    /// // 3) Single T
570    /// let mut mv = MultiValues::Empty(DataType::Int32);
571    /// mv.set(42).unwrap();
572    /// assert_eq!(mv.get_int32s().unwrap(), &[42]);
573    ///
574    /// // String example
575    /// let mut mv = MultiValues::Empty(DataType::String);
576    /// mv.set(vec!["hello".to_string(), "world".to_string()]).unwrap();
577    /// assert_eq!(mv.get_strings().unwrap(), &["hello", "world"]);
578    /// ```
579    #[inline]
580    pub fn set<'a, S>(&mut self, values: S) -> ValueResult<()>
581    where
582        S: MultiValuesSetArg<'a>,
583        Self: MultiValuesSetter<S::Item>
584            + MultiValuesSetterSlice<S::Item>
585            + MultiValuesSingleSetter<S::Item>,
586    {
587        values.apply(self)
588    }
589
590    /// Generic add method
591    ///
592    /// Automatically selects the optimal add path based on the input type,
593    /// appending elements to the existing list with strict type checking.
594    ///
595    /// Supports three input forms:
596    ///
597    /// - `T`: Takes `add_value(T)` path, appending a single element
598    /// - `Vec<T>`: Takes `add_values(Vec<T>)` path, batch append (zero additional allocation)
599    /// - `&[T]`: Takes `add_values_slice(&[T])` path, batch append (using slice)
600    ///
601    /// # Type Parameters
602    ///
603    /// * `S` - Input type, can be a single `T`, `Vec<T>`, or `&[T]`
604    ///
605    /// # Example
606    ///
607    /// ```rust
608    /// use qubit_common::lang::DataType;
609    /// use qubit_value::MultiValues;
610    ///
611    /// // 1) Single T
612    /// let mut mv = MultiValues::Int32(vec![42]);
613    /// mv.add(100).unwrap();
614    /// assert_eq!(mv.get_int32s().unwrap(), &[42, 100]);
615    ///
616    /// // 2) Vec<T>
617    /// mv.add(vec![200, 300]).unwrap();
618    /// assert_eq!(mv.get_int32s().unwrap(), &[42, 100, 200, 300]);
619    ///
620    /// // 3) &[T]
621    /// let slice = &[400, 500][..];
622    /// mv.add(slice).unwrap();
623    /// assert_eq!(mv.get_int32s().unwrap(), &[42, 100, 200, 300, 400, 500]);
624    /// ```
625    #[inline]
626    pub fn add<'a, S>(&mut self, values: S) -> ValueResult<()>
627    where
628        S: MultiValuesAddArg<'a>,
629        Self: MultiValuesAdder<S::Item> + MultiValuesMultiAdder<S::Item>,
630    {
631        values.apply_add(self)
632    }
633
634    /// Get the data type of the values
635    ///
636    /// # Returns
637    ///
638    /// Returns the data type corresponding to these multiple values
639    ///
640    /// # Example
641    ///
642    /// ```rust
643    /// use qubit_common::lang::DataType;
644    /// use qubit_value::MultiValues;
645    ///
646    /// let values = MultiValues::Int32(vec![1, 2, 3]);
647    /// assert_eq!(values.data_type(), DataType::Int32);
648    /// ```
649    #[inline]
650    pub fn data_type(&self) -> DataType {
651        match self {
652            MultiValues::Empty(dt) => *dt,
653            MultiValues::Bool(_) => DataType::Bool,
654            MultiValues::Char(_) => DataType::Char,
655            MultiValues::Int8(_) => DataType::Int8,
656            MultiValues::Int16(_) => DataType::Int16,
657            MultiValues::Int32(_) => DataType::Int32,
658            MultiValues::Int64(_) => DataType::Int64,
659            MultiValues::Int128(_) => DataType::Int128,
660            MultiValues::UInt8(_) => DataType::UInt8,
661            MultiValues::UInt16(_) => DataType::UInt16,
662            MultiValues::UInt32(_) => DataType::UInt32,
663            MultiValues::UInt64(_) => DataType::UInt64,
664            MultiValues::UInt128(_) => DataType::UInt128,
665            MultiValues::Float32(_) => DataType::Float32,
666            MultiValues::Float64(_) => DataType::Float64,
667            MultiValues::String(_) => DataType::String,
668            MultiValues::Date(_) => DataType::Date,
669            MultiValues::Time(_) => DataType::Time,
670            MultiValues::DateTime(_) => DataType::DateTime,
671            MultiValues::Instant(_) => DataType::Instant,
672            MultiValues::BigInteger(_) => DataType::BigInteger,
673            MultiValues::BigDecimal(_) => DataType::BigDecimal,
674            MultiValues::IntSize(_) => DataType::IntSize,
675            MultiValues::UIntSize(_) => DataType::UIntSize,
676            MultiValues::Duration(_) => DataType::Duration,
677            MultiValues::Url(_) => DataType::Url,
678            MultiValues::StringMap(_) => DataType::StringMap,
679            MultiValues::Json(_) => DataType::Json,
680        }
681    }
682
683    /// Get the number of values
684    ///
685    /// # Returns
686    ///
687    /// Returns the number of values contained in these multiple values
688    ///
689    /// # Example
690    ///
691    /// ```rust
692    /// use qubit_common::lang::DataType;
693    /// use qubit_value::MultiValues;
694    ///
695    /// let values = MultiValues::Int32(vec![1, 2, 3]);
696    /// assert_eq!(values.count(), 3);
697    ///
698    /// let empty = MultiValues::Empty(DataType::String);
699    /// assert_eq!(empty.count(), 0);
700    /// ```
701    #[inline]
702    pub fn count(&self) -> usize {
703        match self {
704            MultiValues::Empty(_) => 0,
705            MultiValues::Bool(v) => v.len(),
706            MultiValues::Char(v) => v.len(),
707            MultiValues::Int8(v) => v.len(),
708            MultiValues::Int16(v) => v.len(),
709            MultiValues::Int32(v) => v.len(),
710            MultiValues::Int64(v) => v.len(),
711            MultiValues::Int128(v) => v.len(),
712            MultiValues::UInt8(v) => v.len(),
713            MultiValues::UInt16(v) => v.len(),
714            MultiValues::UInt32(v) => v.len(),
715            MultiValues::UInt64(v) => v.len(),
716            MultiValues::UInt128(v) => v.len(),
717            MultiValues::Float32(v) => v.len(),
718            MultiValues::Float64(v) => v.len(),
719            MultiValues::String(v) => v.len(),
720            MultiValues::Date(v) => v.len(),
721            MultiValues::Time(v) => v.len(),
722            MultiValues::DateTime(v) => v.len(),
723            MultiValues::Instant(v) => v.len(),
724            MultiValues::BigInteger(v) => v.len(),
725            MultiValues::BigDecimal(v) => v.len(),
726            MultiValues::IntSize(v) => v.len(),
727            MultiValues::UIntSize(v) => v.len(),
728            MultiValues::Duration(v) => v.len(),
729            MultiValues::Url(v) => v.len(),
730            MultiValues::StringMap(v) => v.len(),
731            MultiValues::Json(v) => v.len(),
732        }
733    }
734
735    /// Check if empty
736    ///
737    /// # Returns
738    ///
739    /// Returns `true` if these multiple values do not contain any values
740    ///
741    /// # Example
742    ///
743    /// ```rust
744    /// use qubit_common::lang::DataType;
745    /// use qubit_value::MultiValues;
746    ///
747    /// let values = MultiValues::Int32(vec![]);
748    /// assert!(values.is_empty());
749    ///
750    /// let empty = MultiValues::Empty(DataType::String);
751    /// assert!(empty.is_empty());
752    /// ```
753    #[inline]
754    pub fn is_empty(&self) -> bool {
755        self.count() == 0
756    }
757
758    /// Clear all values while preserving the type
759    ///
760    /// # Example
761    ///
762    /// ```rust
763    /// use qubit_common::lang::DataType;
764    /// use qubit_value::MultiValues;
765    ///
766    /// let mut values = MultiValues::Int32(vec![1, 2, 3]);
767    /// values.clear();
768    /// assert!(values.is_empty());
769    /// assert_eq!(values.data_type(), DataType::Int32);
770    /// ```
771    #[inline]
772    pub fn clear(&mut self) {
773        match self {
774            MultiValues::Empty(_) => {}
775            MultiValues::Bool(v) => v.clear(),
776            MultiValues::Char(v) => v.clear(),
777            MultiValues::Int8(v) => v.clear(),
778            MultiValues::Int16(v) => v.clear(),
779            MultiValues::Int32(v) => v.clear(),
780            MultiValues::Int64(v) => v.clear(),
781            MultiValues::Int128(v) => v.clear(),
782            MultiValues::UInt8(v) => v.clear(),
783            MultiValues::UInt16(v) => v.clear(),
784            MultiValues::UInt32(v) => v.clear(),
785            MultiValues::UInt64(v) => v.clear(),
786            MultiValues::UInt128(v) => v.clear(),
787            MultiValues::Float32(v) => v.clear(),
788            MultiValues::Float64(v) => v.clear(),
789            MultiValues::String(v) => v.clear(),
790            MultiValues::Date(v) => v.clear(),
791            MultiValues::Time(v) => v.clear(),
792            MultiValues::DateTime(v) => v.clear(),
793            MultiValues::Instant(v) => v.clear(),
794            MultiValues::BigInteger(v) => v.clear(),
795            MultiValues::BigDecimal(v) => v.clear(),
796            MultiValues::IntSize(v) => v.clear(),
797            MultiValues::UIntSize(v) => v.clear(),
798            MultiValues::Duration(v) => v.clear(),
799            MultiValues::Url(v) => v.clear(),
800            MultiValues::StringMap(v) => v.clear(),
801            MultiValues::Json(v) => v.clear(),
802        }
803    }
804
805    /// Set the data type
806    ///
807    /// If the new type differs from the current type, clears all values and
808    /// sets the new type.
809    ///
810    /// # Parameters
811    ///
812    /// * `data_type` - The data type to set
813    ///
814    /// # Example
815    ///
816    /// ```rust
817    /// use qubit_common::lang::DataType;
818    /// use qubit_value::MultiValues;
819    ///
820    /// let mut values = MultiValues::Int32(vec![1, 2, 3]);
821    /// values.set_type(DataType::String);
822    /// assert!(values.is_empty());
823    /// assert_eq!(values.data_type(), DataType::String);
824    /// ```
825    #[inline]
826    pub fn set_type(&mut self, data_type: DataType) {
827        if self.data_type() != data_type {
828            *self = MultiValues::Empty(data_type);
829        }
830    }
831
832    // ========================================================================
833    // Get first value (as single value access)
834    // ========================================================================
835
836    impl_get_first_value! {
837        /// Get the first boolean value.
838        ///
839        /// # Returns
840        ///
841        /// If types match and a value exists, returns the first boolean value;
842        /// otherwise returns an error.
843        ///
844        /// # Example
845        ///
846        /// ```rust
847        /// use qubit_value::MultiValues;
848        ///
849        /// let values = MultiValues::Bool(vec![true, false]);
850        /// assert_eq!(values.get_first_bool().unwrap(), true);
851        /// ```
852        copy: get_first_bool, Bool, bool, DataType::Bool
853    }
854
855    impl_get_first_value! {
856        /// Get the first character value
857        ///
858        /// # Returns
859        ///
860        /// If types match and a value exists, returns the first character value;
861        /// otherwise returns an error.
862        copy: get_first_char, Char, char, DataType::Char
863    }
864
865    impl_get_first_value! {
866        /// Get the first int8 value
867        ///
868        /// # Returns
869        ///
870        /// If types match and a value exists, returns the first int8 value;
871        /// otherwise returns an error
872        copy: get_first_int8, Int8, i8, DataType::Int8
873    }
874
875    impl_get_first_value! {
876        /// Get the first int16 value
877        ///
878        /// # Returns
879        ///
880        /// If types match and a value exists, returns the first int16 value;
881        /// otherwise returns an error
882        copy: get_first_int16, Int16, i16, DataType::Int16
883    }
884
885    impl_get_first_value! {
886        /// Get the first int32 value
887        ///
888        /// # Returns
889        ///
890        /// If types match and a value exists, returns the first int32 value;
891        /// otherwise returns an error
892        copy: get_first_int32, Int32, i32, DataType::Int32
893    }
894
895    impl_get_first_value! {
896        /// Get the first int64 value
897        ///
898        /// # Returns
899        ///
900        /// If types match and a value exists, returns the first int64 value;
901        /// otherwise returns an error
902        copy: get_first_int64, Int64, i64, DataType::Int64
903    }
904
905    impl_get_first_value! {
906        /// Get the first int128 value
907        ///
908        /// # Returns
909        ///
910        /// If types match and a value exists, returns the first int128 value;
911        /// otherwise returns an error
912        copy: get_first_int128, Int128, i128, DataType::Int128
913    }
914
915    impl_get_first_value! {
916        /// Get the first uint8 value
917        ///
918        /// # Returns
919        ///
920        /// If types match and a value exists, returns the first uint8 value;
921        /// otherwise returns an error
922        copy: get_first_uint8, UInt8, u8, DataType::UInt8
923    }
924
925    impl_get_first_value! {
926        /// Get the first uint16 value
927        ///
928        /// # Returns
929        ///
930        /// If types match and a value exists, returns the first uint16 value;
931        /// otherwise returns an error
932        copy: get_first_uint16, UInt16, u16, DataType::UInt16
933    }
934
935    impl_get_first_value! {
936        /// Get the first uint32 value
937        ///
938        /// # Returns
939        ///
940        /// If types match and a value exists, returns the first uint32 value;
941        /// otherwise returns an error
942        copy: get_first_uint32, UInt32, u32, DataType::UInt32
943    }
944
945    impl_get_first_value! {
946        /// Get the first uint64 value
947        ///
948        /// # Returns
949        ///
950        /// If types match and a value exists, returns the first uint64 value;
951        /// otherwise returns an error
952        copy: get_first_uint64, UInt64, u64, DataType::UInt64
953    }
954
955    impl_get_first_value! {
956        /// Get the first uint128 value
957        ///
958        /// # Returns
959        ///
960        /// If types match and a value exists, returns the first uint128 value;
961        /// otherwise returns an error
962        copy: get_first_uint128, UInt128, u128, DataType::UInt128
963    }
964
965    impl_get_first_value! {
966        /// Get the first float32 value
967        ///
968        /// # Returns
969        ///
970        /// If types match and a value exists, returns the first float32 value;
971        /// otherwise returns an error
972        copy: get_first_float32, Float32, f32, DataType::Float32
973    }
974
975    impl_get_first_value! {
976        /// Get the first float64 value
977        ///
978        /// # Returns
979        ///
980        /// If types match and a value exists, returns the first float64 value;
981        /// otherwise returns an error
982        copy: get_first_float64, Float64, f64, DataType::Float64
983    }
984
985    impl_get_first_value! {
986        /// Get the first string reference
987        ///
988        /// # Returns
989        ///
990        /// If types match and a value exists, returns a reference to the first
991        /// string; otherwise returns an error
992        ref: get_first_string, String, &str, DataType::String, |s: &String| s.as_str()
993    }
994
995    impl_get_first_value! {
996        /// Get the first date value
997        ///
998        /// # Returns
999        ///
1000        /// If types match and a value exists, returns the first date value;
1001        /// otherwise returns an error
1002        copy: get_first_date, Date, NaiveDate, DataType::Date
1003    }
1004
1005    impl_get_first_value! {
1006        /// Get the first time value
1007        ///
1008        /// # Returns
1009        ///
1010        /// If types match and a value exists, returns the first time value;
1011        /// otherwise returns an error
1012        copy: get_first_time, Time, NaiveTime, DataType::Time
1013    }
1014
1015    impl_get_first_value! {
1016        /// Get the first datetime value
1017        ///
1018        /// # Returns
1019        ///
1020        /// If types match and a value exists, returns the first datetime value;
1021        /// otherwise returns an error
1022        copy: get_first_datetime, DateTime, NaiveDateTime, DataType::DateTime
1023    }
1024
1025    impl_get_first_value! {
1026        /// Get the first UTC instant value
1027        ///
1028        /// # Returns
1029        ///
1030        /// If types match and a value exists, returns the first UTC instant
1031        /// value; otherwise returns an error
1032        copy: get_first_instant, Instant, DateTime<Utc>, DataType::Instant
1033    }
1034
1035    impl_get_first_value! {
1036        /// Get the first big integer value
1037        ///
1038        /// # Returns
1039        ///
1040        /// If types match and a value exists, returns the first big integer
1041        /// value; otherwise returns an error
1042        ref: get_first_biginteger, BigInteger, BigInt, DataType::BigInteger, |v: &BigInt| v.clone()
1043    }
1044
1045    impl_get_first_value! {
1046        /// Get the first big decimal value
1047        ///
1048        /// # Returns
1049        ///
1050        /// If types match and a value exists, returns the first big decimal
1051        /// value; otherwise returns an error
1052        ref: get_first_bigdecimal, BigDecimal, BigDecimal, DataType::BigDecimal, |v: &BigDecimal| v.clone()
1053    }
1054
1055    impl_get_first_value! {
1056        /// Get the first isize value
1057        copy: get_first_intsize, IntSize, isize, DataType::IntSize
1058    }
1059
1060    impl_get_first_value! {
1061        /// Get the first usize value
1062        copy: get_first_uintsize, UIntSize, usize, DataType::UIntSize
1063    }
1064
1065    impl_get_first_value! {
1066        /// Get the first Duration value
1067        copy: get_first_duration, Duration, Duration, DataType::Duration
1068    }
1069
1070    impl_get_first_value! {
1071        /// Get the first Url value
1072        ref: get_first_url, Url, Url, DataType::Url, |v: &Url| v.clone()
1073    }
1074
1075    impl_get_first_value! {
1076        /// Get the first StringMap value
1077        ref: get_first_string_map, StringMap, HashMap<String, String>, DataType::StringMap, |v: &HashMap<String, String>| v.clone()
1078    }
1079
1080    impl_get_first_value! {
1081        /// Get the first Json value
1082        ref: get_first_json, Json, serde_json::Value, DataType::Json, |v: &serde_json::Value| v.clone()
1083    }
1084
1085    // ========================================================================
1086    // Get all values (type checking)
1087    // ========================================================================
1088
1089    impl_get_multi_values! {
1090        /// Get reference to all boolean values
1091        ///
1092        /// # Returns
1093        ///
1094        /// If types match, returns a reference to the boolean value array;
1095        /// otherwise returns an error
1096        ///
1097        /// # Example
1098        ///
1099        /// ```rust
1100        /// use qubit_value::MultiValues;
1101        ///
1102        /// let values = MultiValues::Bool(vec![true, false, true]);
1103        /// assert_eq!(values.get_bools().unwrap(), &[true, false, true]);
1104        /// ```
1105        slice: get_bools, Bool, bool, DataType::Bool
1106    }
1107
1108    impl_get_multi_values! {
1109        /// Get reference to all character values
1110        ///
1111        /// # Returns
1112        ///
1113        /// If types match, returns a reference to the character value array;
1114        /// otherwise returns an error
1115        slice: get_chars, Char, char, DataType::Char
1116    }
1117
1118    impl_get_multi_values! {
1119        /// Get reference to all int8 values
1120        ///
1121        /// # Returns
1122        ///
1123        /// If types match, returns a reference to the int8 value array;
1124        /// otherwise returns an error
1125        slice: get_int8s, Int8, i8, DataType::Int8
1126    }
1127
1128    impl_get_multi_values! {
1129        /// Get reference to all int16 values
1130        ///
1131        /// # Returns
1132        ///
1133        /// If types match, returns a reference to the int16 value array;
1134        /// otherwise returns an error
1135        slice: get_int16s, Int16, i16, DataType::Int16
1136    }
1137
1138    impl_get_multi_values! {
1139        /// Get reference to all int32 values
1140        ///
1141        /// # Returns
1142        ///
1143        /// If types match, returns a reference to the int32 value array;
1144        /// otherwise returns an error
1145        slice: get_int32s, Int32, i32, DataType::Int32
1146    }
1147
1148    impl_get_multi_values! {
1149        /// Get reference to all int64 values
1150        ///
1151        /// # Returns
1152        ///
1153        /// If types match, returns a reference to the int64 value array;
1154        /// otherwise returns an error
1155        slice: get_int64s, Int64, i64, DataType::Int64
1156    }
1157
1158    impl_get_multi_values! {
1159        /// Get reference to all int128 values
1160        ///
1161        /// # Returns
1162        ///
1163        /// If types match, returns a reference to the int128 value array;
1164        /// otherwise returns an error
1165        slice: get_int128s, Int128, i128, DataType::Int128
1166    }
1167
1168    impl_get_multi_values! {
1169        /// Get reference to all uint8 values
1170        ///
1171        /// # Returns
1172        ///
1173        /// If types match, returns a reference to the uint8 value array;
1174        /// otherwise returns an error
1175        slice: get_uint8s, UInt8, u8, DataType::UInt8
1176    }
1177
1178    impl_get_multi_values! {
1179        /// Get reference to all uint16 values
1180        ///
1181        /// # Returns
1182        ///
1183        /// If types match, returns a reference to the uint16 value array;
1184        /// otherwise returns an error
1185        slice: get_uint16s, UInt16, u16, DataType::UInt16
1186    }
1187
1188    impl_get_multi_values! {
1189        /// Get reference to all uint32 values
1190        ///
1191        /// # Returns
1192        ///
1193        /// If types match, returns a reference to the uint32 value array;
1194        /// otherwise returns an error
1195        slice: get_uint32s, UInt32, u32, DataType::UInt32
1196    }
1197
1198    impl_get_multi_values! {
1199        /// Get reference to all uint64 values
1200        ///
1201        /// # Returns
1202        ///
1203        /// If types match, returns a reference to the uint64 value array;
1204        /// otherwise returns an error
1205        slice: get_uint64s, UInt64, u64, DataType::UInt64
1206    }
1207
1208    impl_get_multi_values! {
1209        /// Get reference to all uint128 values
1210        ///
1211        /// # Returns
1212        ///
1213        /// If types match, returns a reference to the uint128 value array;
1214        /// otherwise returns an error
1215        slice: get_uint128s, UInt128, u128, DataType::UInt128
1216    }
1217
1218    impl_get_multi_values! {
1219        /// Get reference to all float32 values
1220        ///
1221        /// # Returns
1222        ///
1223        /// If types match, returns a reference to the float32 value array;
1224        /// otherwise returns an error
1225        slice: get_float32s, Float32, f32, DataType::Float32
1226    }
1227
1228    impl_get_multi_values! {
1229        /// Get reference to all float64 values
1230        ///
1231        /// # Returns
1232        ///
1233        /// If types match, returns a reference to the float64 value array;
1234        /// otherwise returns an error
1235        slice: get_float64s, Float64, f64, DataType::Float64
1236    }
1237
1238    impl_get_multi_values! {
1239        /// Get reference to all strings
1240        ///
1241        /// # Returns
1242        ///
1243        /// If types match, returns a reference to the string array; otherwise
1244        /// returns an error
1245        vec: get_strings, String, String, DataType::String
1246    }
1247
1248    impl_get_multi_values! {
1249        /// Get reference to all date values
1250        ///
1251        /// # Returns
1252        ///
1253        /// If types match, returns a reference to the date value array;
1254        /// otherwise returns an error
1255        slice: get_dates, Date, NaiveDate, DataType::Date
1256    }
1257
1258    impl_get_multi_values! {
1259        /// Get reference to all time values
1260        ///
1261        /// # Returns
1262        ///
1263        /// If types match, returns a reference to the time value array;
1264        /// otherwise returns an error
1265        slice: get_times, Time, NaiveTime, DataType::Time
1266    }
1267
1268    impl_get_multi_values! {
1269        /// Get reference to all datetime values
1270        ///
1271        /// # Returns
1272        ///
1273        /// If types match, returns a reference to the datetime value array;
1274        /// otherwise returns an error
1275        slice: get_datetimes, DateTime, NaiveDateTime, DataType::DateTime
1276    }
1277
1278    impl_get_multi_values! {
1279        /// Get reference to all UTC instant values
1280        ///
1281        /// # Returns
1282        ///
1283        /// If types match, returns a reference to the UTC instant value array;
1284        /// otherwise returns an error
1285        slice: get_instants, Instant, DateTime<Utc>, DataType::Instant
1286    }
1287
1288    impl_get_multi_values! {
1289        /// Get reference to all big integers
1290        ///
1291        /// # Returns
1292        ///
1293        /// If types match, returns a reference to the big integer array;
1294        /// otherwise returns an error
1295        vec: get_bigintegers, BigInteger, BigInt, DataType::BigInteger
1296    }
1297
1298    impl_get_multi_values! {
1299        /// Get reference to all big decimals
1300        ///
1301        /// # Returns
1302        ///
1303        /// If types match, returns a reference to the big decimal array;
1304        /// otherwise returns an error
1305        vec: get_bigdecimals, BigDecimal, BigDecimal, DataType::BigDecimal
1306    }
1307
1308    impl_get_multi_values! {
1309        /// Get reference to all isize values
1310        slice: get_intsizes, IntSize, isize, DataType::IntSize
1311    }
1312
1313    impl_get_multi_values! {
1314        /// Get reference to all usize values
1315        slice: get_uintsizes, UIntSize, usize, DataType::UIntSize
1316    }
1317
1318    impl_get_multi_values! {
1319        /// Get reference to all Duration values
1320        slice: get_durations, Duration, Duration, DataType::Duration
1321    }
1322
1323    impl_get_multi_values! {
1324        /// Get reference to all Url values
1325        vec: get_urls, Url, Url, DataType::Url
1326    }
1327
1328    impl_get_multi_values! {
1329        /// Get reference to all StringMap values
1330        vec: get_string_maps, StringMap, HashMap<String, String>, DataType::StringMap
1331    }
1332
1333    impl_get_multi_values! {
1334        /// Get reference to all Json values
1335        vec: get_jsons, Json, serde_json::Value, DataType::Json
1336    }
1337
1338    // ========================================================================
1339    // Set value operations
1340    // ========================================================================
1341
1342    impl_set_multi_values! {
1343        /// Set all boolean values
1344        ///
1345        /// # Parameters
1346        ///
1347        /// * `values` - The list of boolean values to set
1348        ///
1349        /// # Returns
1350        ///
1351        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1352        ///
1353        /// # Example
1354        ///
1355        /// ```rust
1356        /// use qubit_common::lang::DataType;
1357        /// use qubit_value::MultiValues;
1358        ///
1359        /// let mut values = MultiValues::Empty(DataType::Bool);
1360        /// values.set_bools(vec![true, false, true]).unwrap();
1361        /// assert_eq!(values.get_bools().unwrap(), &[true, false, true]);
1362        /// ```
1363        set_bools, Bool, bool, DataType::Bool
1364    }
1365
1366    impl_set_multi_values! {
1367        /// Set all character values
1368        ///
1369        /// # Parameters
1370        ///
1371        /// * `values` - The list of character values to set
1372        ///
1373        /// # Returns
1374        ///
1375        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1376        set_chars, Char, char, DataType::Char
1377    }
1378
1379    impl_set_multi_values! {
1380        /// Set all int8 values
1381        ///
1382        /// # Parameters
1383        ///
1384        /// * `values` - The list of int8 values to set
1385        ///
1386        /// # Returns
1387        ///
1388        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1389        set_int8s, Int8, i8, DataType::Int8
1390    }
1391
1392    impl_set_multi_values! {
1393        /// Set all int16 values
1394        ///
1395        /// # Parameters
1396        ///
1397        /// * `values` - The list of int16 values to set
1398        ///
1399        /// # Returns
1400        ///
1401        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1402        set_int16s, Int16, i16, DataType::Int16
1403    }
1404
1405    impl_set_multi_values! {
1406        /// Set all int32 values
1407        ///
1408        /// # Parameters
1409        ///
1410        /// * `values` - The list of int32 values to set
1411        ///
1412        /// # Returns
1413        ///
1414        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1415        set_int32s, Int32, i32, DataType::Int32
1416    }
1417
1418    impl_set_multi_values! {
1419        /// Set all int64 values
1420        ///
1421        /// # Parameters
1422        ///
1423        /// * `values` - The list of int64 values to set
1424        ///
1425        /// # Returns
1426        ///
1427        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1428        set_int64s, Int64, i64, DataType::Int64
1429    }
1430
1431    impl_set_multi_values! {
1432        /// Set all int128 values
1433        ///
1434        /// # Parameters
1435        ///
1436        /// * `values` - The list of int128 values to set
1437        ///
1438        /// # Returns
1439        ///
1440        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1441        set_int128s, Int128, i128, DataType::Int128
1442    }
1443
1444    impl_set_multi_values! {
1445        /// Set all uint8 values
1446        ///
1447        /// # Parameters
1448        ///
1449        /// * `values` - The list of uint8 values to set
1450        ///
1451        /// # Returns
1452        ///
1453        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1454        set_uint8s, UInt8, u8, DataType::UInt8
1455    }
1456
1457    impl_set_multi_values! {
1458        /// Set all uint16 values
1459        ///
1460        /// # Parameters
1461        ///
1462        /// * `values` - The list of uint16 values to set
1463        ///
1464        /// # Returns
1465        ///
1466        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1467        set_uint16s, UInt16, u16, DataType::UInt16
1468    }
1469
1470    impl_set_multi_values! {
1471        /// Set all uint32 values
1472        ///
1473        /// # Parameters
1474        ///
1475        /// * `values` - The list of uint32 values to set
1476        ///
1477        /// # Returns
1478        ///
1479        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1480        set_uint32s, UInt32, u32, DataType::UInt32
1481    }
1482
1483    impl_set_multi_values! {
1484        /// Set all uint64 values
1485        ///
1486        /// # Parameters
1487        ///
1488        /// * `values` - The list of uint64 values to set
1489        ///
1490        /// # Returns
1491        ///
1492        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1493        set_uint64s, UInt64, u64, DataType::UInt64
1494    }
1495
1496    impl_set_multi_values! {
1497        /// Set all uint128 values
1498        ///
1499        /// # Parameters
1500        ///
1501        /// * `values` - The list of uint128 values to set
1502        ///
1503        /// # Returns
1504        ///
1505        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1506        set_uint128s, UInt128, u128, DataType::UInt128
1507    }
1508
1509    impl_set_multi_values! {
1510        /// Set all float32 values
1511        ///
1512        /// # Parameters
1513        ///
1514        /// * `values` - The list of float32 values to set
1515        ///
1516        /// # Returns
1517        ///
1518        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1519        set_float32s, Float32, f32, DataType::Float32
1520    }
1521
1522    impl_set_multi_values! {
1523        /// Set all float64 values
1524        ///
1525        /// # Parameters
1526        ///
1527        /// * `values` - The list of float64 values to set
1528        ///
1529        /// # Returns
1530        ///
1531        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1532        set_float64s, Float64, f64, DataType::Float64
1533    }
1534
1535    impl_set_multi_values! {
1536        /// Set all string values
1537        ///
1538        /// # Parameters
1539        ///
1540        /// * `values` - The list of string values to set
1541        ///
1542        /// # Returns
1543        ///
1544        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1545        ///
1546        /// # Example
1547        ///
1548        /// ```rust
1549        /// use qubit_common::lang::DataType;
1550        /// use qubit_value::MultiValues;
1551        ///
1552        /// let mut values = MultiValues::Empty(DataType::String);
1553        /// values.set_strings(vec!["hello".to_string(), "world".to_string()]).unwrap();
1554        /// assert_eq!(values.get_strings().unwrap(), &["hello", "world"]);
1555        /// ```
1556        set_strings, String, String, DataType::String
1557    }
1558
1559    impl_set_multi_values! {
1560        /// Set all date values
1561        ///
1562        /// # Parameters
1563        ///
1564        /// * `values` - The list of date values to set
1565        ///
1566        /// # Returns
1567        ///
1568        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1569        set_dates, Date, NaiveDate, DataType::Date
1570    }
1571
1572    impl_set_multi_values! {
1573        /// Set all time values
1574        ///
1575        /// # Parameters
1576        ///
1577        /// * `values` - The list of time values to set
1578        ///
1579        /// # Returns
1580        ///
1581        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1582        set_times, Time, NaiveTime, DataType::Time
1583    }
1584
1585    impl_set_multi_values! {
1586        /// Set all datetime values
1587        ///
1588        /// # Parameters
1589        ///
1590        /// * `values` - The list of datetime values to set
1591        ///
1592        /// # Returns
1593        ///
1594        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1595        set_datetimes, DateTime, NaiveDateTime, DataType::DateTime
1596    }
1597
1598    impl_set_multi_values! {
1599        /// Set all UTC instant values
1600        ///
1601        /// # Parameters
1602        ///
1603        /// * `values` - The list of UTC instant values to set
1604        ///
1605        /// # Returns
1606        ///
1607        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1608        set_instants, Instant, DateTime<Utc>, DataType::Instant
1609    }
1610
1611    impl_set_multi_values! {
1612        /// Set all big integer values
1613        ///
1614        /// # Parameters
1615        ///
1616        /// * `values` - The list of big integer values to set
1617        ///
1618        /// # Returns
1619        ///
1620        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1621        set_bigintegers, BigInteger, BigInt, DataType::BigInteger
1622    }
1623
1624    impl_set_multi_values! {
1625        /// Set all big decimal values
1626        ///
1627        /// # Parameters
1628        ///
1629        /// * `values` - The list of big decimal values to set
1630        ///
1631        /// # Returns
1632        ///
1633        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1634        set_bigdecimals, BigDecimal, BigDecimal, DataType::BigDecimal
1635    }
1636
1637    impl_set_multi_values! {
1638        /// Set all isize values
1639        set_intsizes, IntSize, isize, DataType::IntSize
1640    }
1641
1642    impl_set_multi_values! {
1643        /// Set all usize values
1644        set_uintsizes, UIntSize, usize, DataType::UIntSize
1645    }
1646
1647    impl_set_multi_values! {
1648        /// Set all Duration values
1649        set_durations, Duration, Duration, DataType::Duration
1650    }
1651
1652    impl_set_multi_values! {
1653        /// Set all Url values
1654        set_urls, Url, Url, DataType::Url
1655    }
1656
1657    impl_set_multi_values! {
1658        /// Set all StringMap values
1659        set_string_maps, StringMap, HashMap<String, String>, DataType::StringMap
1660    }
1661
1662    impl_set_multi_values! {
1663        /// Set all Json values
1664        set_jsons, Json, serde_json::Value, DataType::Json
1665    }
1666
1667    // ========================================================================
1668    // Set all values via slice operations
1669    // ========================================================================
1670
1671    impl_set_multi_values_slice! {
1672        /// Set all boolean values via slice
1673        ///
1674        /// # Parameters
1675        ///
1676        /// * `values` - The boolean value slice to set
1677        ///
1678        /// # Returns
1679        ///
1680        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1681        set_bools_slice, Bool, bool, DataType::Bool
1682    }
1683
1684    impl_set_multi_values_slice! {
1685        /// Set all character values via slice
1686        ///
1687        /// # Parameters
1688        ///
1689        /// * `values` - The character value slice to set
1690        ///
1691        /// # Returns
1692        ///
1693        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1694        set_chars_slice, Char, char, DataType::Char
1695    }
1696
1697    impl_set_multi_values_slice! {
1698        /// Set all int8 values via slice
1699        ///
1700        /// # Parameters
1701        ///
1702        /// * `values` - The int8 value slice to set
1703        ///
1704        /// # Returns
1705        ///
1706        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1707        set_int8s_slice, Int8, i8, DataType::Int8
1708    }
1709
1710    impl_set_multi_values_slice! {
1711        /// Set all int16 values via slice
1712        ///
1713        /// # Parameters
1714        ///
1715        /// * `values` - The int16 value slice to set
1716        ///
1717        /// # Returns
1718        ///
1719        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1720        set_int16s_slice, Int16, i16, DataType::Int16
1721    }
1722
1723    impl_set_multi_values_slice! {
1724        /// Set all int32 values via slice
1725        ///
1726        /// # Parameters
1727        ///
1728        /// * `values` - The int32 value slice to set
1729        ///
1730        /// # Returns
1731        ///
1732        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1733        set_int32s_slice, Int32, i32, DataType::Int32
1734    }
1735
1736    impl_set_multi_values_slice! {
1737        /// Set all int64 values via slice
1738        ///
1739        /// # Parameters
1740        ///
1741        /// * `values` - The int64 value slice to set
1742        ///
1743        /// # Returns
1744        ///
1745        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1746        set_int64s_slice, Int64, i64, DataType::Int64
1747    }
1748
1749    impl_set_multi_values_slice! {
1750        /// Set all int128 values via slice
1751        ///
1752        /// # Parameters
1753        ///
1754        /// * `values` - The int128 value slice to set
1755        ///
1756        /// # Returns
1757        ///
1758        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1759        set_int128s_slice, Int128, i128, DataType::Int128
1760    }
1761
1762    impl_set_multi_values_slice! {
1763        /// Set all uint8 values via slice
1764        ///
1765        /// # Parameters
1766        ///
1767        /// * `values` - The uint8 value slice to set
1768        ///
1769        /// # Returns
1770        ///
1771        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1772        set_uint8s_slice, UInt8, u8, DataType::UInt8
1773    }
1774
1775    impl_set_multi_values_slice! {
1776        /// Set all uint16 values via slice
1777        ///
1778        /// # Parameters
1779        ///
1780        /// * `values` - The uint16 value slice to set
1781        ///
1782        /// # Returns
1783        ///
1784        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1785        set_uint16s_slice, UInt16, u16, DataType::UInt16
1786    }
1787
1788    impl_set_multi_values_slice! {
1789        /// Set all uint32 values via slice
1790        ///
1791        /// # Parameters
1792        ///
1793        /// * `values` - The uint32 value slice to set
1794        ///
1795        /// # Returns
1796        ///
1797        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1798        set_uint32s_slice, UInt32, u32, DataType::UInt32
1799    }
1800
1801    impl_set_multi_values_slice! {
1802        /// Set all uint64 values via slice
1803        ///
1804        /// # Parameters
1805        ///
1806        /// * `values` - The uint64 value slice to set
1807        ///
1808        /// # Returns
1809        ///
1810        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1811        set_uint64s_slice, UInt64, u64, DataType::UInt64
1812    }
1813
1814    impl_set_multi_values_slice! {
1815        /// Set all uint128 values via slice
1816        ///
1817        /// # Parameters
1818        ///
1819        /// * `values` - The uint128 value slice to set
1820        ///
1821        /// # Returns
1822        ///
1823        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1824        set_uint128s_slice, UInt128, u128, DataType::UInt128
1825    }
1826
1827    impl_set_multi_values_slice! {
1828        /// Set all float32 values via slice
1829        ///
1830        /// # Parameters
1831        ///
1832        /// * `values` - The float32 value slice to set
1833        ///
1834        /// # Returns
1835        ///
1836        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1837        set_float32s_slice, Float32, f32, DataType::Float32
1838    }
1839
1840    impl_set_multi_values_slice! {
1841        /// Set all float64 values via slice
1842        ///
1843        /// # Parameters
1844        ///
1845        /// * `values` - The float64 value slice to set
1846        ///
1847        /// # Returns
1848        ///
1849        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1850        set_float64s_slice, Float64, f64, DataType::Float64
1851    }
1852
1853    impl_set_multi_values_slice! {
1854        /// Set all string values via slice
1855        ///
1856        /// # Parameters
1857        ///
1858        /// * `values` - The string value slice to set
1859        ///
1860        /// # Returns
1861        ///
1862        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1863        set_strings_slice, String, String, DataType::String
1864    }
1865
1866    impl_set_multi_values_slice! {
1867        /// Set all date values via slice
1868        ///
1869        /// # Parameters
1870        ///
1871        /// * `values` - The date value slice to set
1872        ///
1873        /// # Returns
1874        ///
1875        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1876        set_dates_slice, Date, NaiveDate, DataType::Date
1877    }
1878
1879    impl_set_multi_values_slice! {
1880        /// Set all time values via slice
1881        ///
1882        /// # Parameters
1883        ///
1884        /// * `values` - The time value slice to set
1885        ///
1886        /// # Returns
1887        ///
1888        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1889        set_times_slice, Time, NaiveTime, DataType::Time
1890    }
1891
1892    impl_set_multi_values_slice! {
1893        /// Set all datetime values via slice
1894        ///
1895        /// # Parameters
1896        ///
1897        /// * `values` - The datetime value slice to set
1898        ///
1899        /// # Returns
1900        ///
1901        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1902        set_datetimes_slice, DateTime, NaiveDateTime, DataType::DateTime
1903    }
1904
1905    impl_set_multi_values_slice! {
1906        /// Set all UTC instant values via slice
1907        ///
1908        /// # Parameters
1909        ///
1910        /// * `values` - The UTC instant value slice to set
1911        ///
1912        /// # Returns
1913        ///
1914        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1915        set_instants_slice, Instant, DateTime<Utc>, DataType::Instant
1916    }
1917
1918    impl_set_multi_values_slice! {
1919        /// Set all big integer values via slice
1920        ///
1921        /// # Parameters
1922        ///
1923        /// * `values` - The big integer value slice to set
1924        ///
1925        /// # Returns
1926        ///
1927        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1928        set_bigintegers_slice, BigInteger, BigInt, DataType::BigInteger
1929    }
1930
1931    impl_set_multi_values_slice! {
1932        /// Set all big decimal values via slice
1933        ///
1934        /// # Parameters
1935        ///
1936        /// * `values` - The big decimal value slice to set
1937        ///
1938        /// # Returns
1939        ///
1940        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1941        set_bigdecimals_slice, BigDecimal, BigDecimal, DataType::BigDecimal
1942    }
1943
1944    impl_set_multi_values_slice! {
1945        /// Set all isize values via slice
1946        set_intsizes_slice, IntSize, isize, DataType::IntSize
1947    }
1948
1949    impl_set_multi_values_slice! {
1950        /// Set all usize values via slice
1951        set_uintsizes_slice, UIntSize, usize, DataType::UIntSize
1952    }
1953
1954    impl_set_multi_values_slice! {
1955        /// Set all Duration values via slice
1956        set_durations_slice, Duration, Duration, DataType::Duration
1957    }
1958
1959    impl_set_multi_values_slice! {
1960        /// Set all Url values via slice
1961        set_urls_slice, Url, Url, DataType::Url
1962    }
1963
1964    impl_set_multi_values_slice! {
1965        /// Set all StringMap values via slice
1966        set_string_maps_slice, StringMap, HashMap<String, String>, DataType::StringMap
1967    }
1968
1969    impl_set_multi_values_slice! {
1970        /// Set all Json values via slice
1971        set_jsons_slice, Json, serde_json::Value, DataType::Json
1972    }
1973
1974    // ========================================================================
1975    // Set single value operations
1976    // ========================================================================
1977
1978    impl_set_single_value! {
1979        /// Set single boolean value
1980        ///
1981        /// # Parameters
1982        ///
1983        /// * `value` - The boolean value to set
1984        ///
1985        /// # Returns
1986        ///
1987        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1988        ///
1989        /// # Example
1990        ///
1991        /// ```rust
1992        /// use qubit_common::lang::DataType;
1993        /// use qubit_value::MultiValues;
1994        ///
1995        /// let mut values = MultiValues::Empty(DataType::Bool);
1996        /// values.set_bool(true).unwrap();
1997        /// assert_eq!(values.get_bools().unwrap(), &[true]);
1998        /// ```
1999        set_bool, Bool, bool, DataType::Bool
2000    }
2001
2002    impl_set_single_value! {
2003        /// Set single character value
2004        ///
2005        /// # Parameters
2006        ///
2007        /// * `value` - The character value to set
2008        ///
2009        /// # Returns
2010        ///
2011        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2012        set_char, Char, char, DataType::Char
2013    }
2014
2015    impl_set_single_value! {
2016        /// Set single int8 value
2017        ///
2018        /// # Parameters
2019        ///
2020        /// * `value` - The int8 value to set
2021        ///
2022        /// # Returns
2023        ///
2024        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2025        set_int8, Int8, i8, DataType::Int8
2026    }
2027
2028    impl_set_single_value! {
2029        /// Set single int16 value
2030        ///
2031        /// # Parameters
2032        ///
2033        /// * `value` - The int16 value to set
2034        ///
2035        /// # Returns
2036        ///
2037        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2038        set_int16, Int16, i16, DataType::Int16
2039    }
2040
2041    impl_set_single_value! {
2042        /// Set single int32 value
2043        ///
2044        /// # Parameters
2045        ///
2046        /// * `value` - The int32 value to set
2047        ///
2048        /// # Returns
2049        ///
2050        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2051        set_int32, Int32, i32, DataType::Int32
2052    }
2053
2054    impl_set_single_value! {
2055        /// Set single int64 value
2056        ///
2057        /// # Parameters
2058        ///
2059        /// * `value` - The int64 value to set
2060        ///
2061        /// # Returns
2062        ///
2063        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2064        set_int64, Int64, i64, DataType::Int64
2065    }
2066
2067    impl_set_single_value! {
2068        /// Set single int128 value
2069        ///
2070        /// # Parameters
2071        ///
2072        /// * `value` - The int128 value to set
2073        ///
2074        /// # Returns
2075        ///
2076        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2077        set_int128, Int128, i128, DataType::Int128
2078    }
2079
2080    impl_set_single_value! {
2081        /// Set single uint8 value
2082        ///
2083        /// # Parameters
2084        ///
2085        /// * `value` - The uint8 value to set
2086        ///
2087        /// # Returns
2088        ///
2089        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2090        set_uint8, UInt8, u8, DataType::UInt8
2091    }
2092
2093    impl_set_single_value! {
2094        /// Set single uint16 value
2095        ///
2096        /// # Parameters
2097        ///
2098        /// * `value` - The uint16 value to set
2099        ///
2100        /// # Returns
2101        ///
2102        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2103        set_uint16, UInt16, u16, DataType::UInt16
2104    }
2105
2106    impl_set_single_value! {
2107        /// Set single uint32 value
2108        ///
2109        /// # Parameters
2110        ///
2111        /// * `value` - The uint32 value to set
2112        ///
2113        /// # Returns
2114        ///
2115        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2116        set_uint32, UInt32, u32, DataType::UInt32
2117    }
2118
2119    impl_set_single_value! {
2120        /// Set single uint64 value
2121        ///
2122        /// # Parameters
2123        ///
2124        /// * `value` - The uint64 value to set
2125        ///
2126        /// # Returns
2127        ///
2128        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2129        set_uint64, UInt64, u64, DataType::UInt64
2130    }
2131
2132    impl_set_single_value! {
2133        /// Set single uint128 value
2134        ///
2135        /// # Parameters
2136        ///
2137        /// * `value` - The uint128 value to set
2138        ///
2139        /// # Returns
2140        ///
2141        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2142        set_uint128, UInt128, u128, DataType::UInt128
2143    }
2144
2145    impl_set_single_value! {
2146        /// Set single float32 value
2147        ///
2148        /// # Parameters
2149        ///
2150        /// * `value` - The float32 value to set
2151        ///
2152        /// # Returns
2153        ///
2154        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2155        set_float32, Float32, f32, DataType::Float32
2156    }
2157
2158    impl_set_single_value! {
2159        /// Set single float64 value
2160        ///
2161        /// # Parameters
2162        ///
2163        /// * `value` - The float64 value to set
2164        ///
2165        /// # Returns
2166        ///
2167        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2168        set_float64, Float64, f64, DataType::Float64
2169    }
2170
2171    impl_set_single_value! {
2172        /// Set single string value
2173        ///
2174        /// # Parameters
2175        ///
2176        /// * `value` - The string value to set
2177        ///
2178        /// # Returns
2179        ///
2180        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2181        ///
2182        /// # Example
2183        ///
2184        /// ```rust
2185        /// use qubit_common::lang::DataType;
2186        /// use qubit_value::MultiValues;
2187        ///
2188        /// let mut values = MultiValues::Empty(DataType::String);
2189        /// values.set_string("hello".to_string()).unwrap();
2190        /// assert_eq!(values.get_strings().unwrap(), &["hello"]);
2191        /// ```
2192        set_string, String, String, DataType::String
2193    }
2194
2195    impl_set_single_value! {
2196        /// Set single date value
2197        ///
2198        /// # Parameters
2199        ///
2200        /// * `value` - The date value to set
2201        ///
2202        /// # Returns
2203        ///
2204        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2205        set_date, Date, NaiveDate, DataType::Date
2206    }
2207
2208    impl_set_single_value! {
2209        /// Set single time value
2210        ///
2211        /// # Parameters
2212        ///
2213        /// * `value` - The time value to set
2214        ///
2215        /// # Returns
2216        ///
2217        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2218        set_time, Time, NaiveTime, DataType::Time
2219    }
2220
2221    impl_set_single_value! {
2222        /// Set single datetime value
2223        ///
2224        /// # Parameters
2225        ///
2226        /// * `value` - The datetime value to set
2227        ///
2228        /// # Returns
2229        ///
2230        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2231        set_datetime, DateTime, NaiveDateTime, DataType::DateTime
2232    }
2233
2234    impl_set_single_value! {
2235        /// Set single UTC instant value
2236        ///
2237        /// # Parameters
2238        ///
2239        /// * `value` - The UTC instant value to set
2240        ///
2241        /// # Returns
2242        ///
2243        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2244        set_instant, Instant, DateTime<Utc>, DataType::Instant
2245    }
2246
2247    impl_set_single_value! {
2248        /// Set single big integer value
2249        ///
2250        /// # Parameters
2251        ///
2252        /// * `value` - The big integer value to set
2253        ///
2254        /// # Returns
2255        ///
2256        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2257        set_biginteger, BigInteger, BigInt, DataType::BigInteger
2258    }
2259
2260    impl_set_single_value! {
2261        /// Set single big decimal value
2262        ///
2263        /// # Parameters
2264        ///
2265        /// * `value` - The big decimal value to set
2266        ///
2267        /// # Returns
2268        ///
2269        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2270        set_bigdecimal, BigDecimal, BigDecimal, DataType::BigDecimal
2271    }
2272
2273    impl_set_single_value! {
2274        /// Set single isize value
2275        set_intsize, IntSize, isize, DataType::IntSize
2276    }
2277
2278    impl_set_single_value! {
2279        /// Set single usize value
2280        set_uintsize, UIntSize, usize, DataType::UIntSize
2281    }
2282
2283    impl_set_single_value! {
2284        /// Set single Duration value
2285        set_duration, Duration, Duration, DataType::Duration
2286    }
2287
2288    impl_set_single_value! {
2289        /// Set single Url value
2290        set_url, Url, Url, DataType::Url
2291    }
2292
2293    impl_set_single_value! {
2294        /// Set single StringMap value
2295        set_string_map, StringMap, HashMap<String, String>, DataType::StringMap
2296    }
2297
2298    impl_set_single_value! {
2299        /// Set single Json value
2300        set_json, Json, serde_json::Value, DataType::Json
2301    }
2302
2303    // ========================================================================
2304    // Add value operations
2305    // ========================================================================
2306
2307    impl_add_single_value! {
2308        /// Add a boolean value
2309        ///
2310        /// # Parameters
2311        ///
2312        /// * `value` - The boolean value to add
2313        ///
2314        /// # Returns
2315        ///
2316        /// If types match, returns `Ok(())`; otherwise returns an error
2317        ///
2318        /// # Example
2319        ///
2320        /// ```rust
2321        /// use qubit_value::MultiValues;
2322        ///
2323        /// let mut values = MultiValues::Bool(vec![true]);
2324        /// values.add_bool(false).unwrap();
2325        /// assert_eq!(values.count(), 2);
2326        /// ```
2327        add_bool, Bool, bool, DataType::Bool
2328    }
2329
2330    impl_add_single_value! {
2331        /// Add a character value
2332        ///
2333        /// # Parameters
2334        ///
2335        /// * `value` - The character value to add
2336        ///
2337        /// # Returns
2338        ///
2339        /// If types match, returns `Ok(())`; otherwise returns an error
2340        add_char, Char, char, DataType::Char
2341    }
2342
2343    impl_add_single_value! {
2344        /// Add an int8 value
2345        ///
2346        /// # Parameters
2347        ///
2348        /// * `value` - The int8 value to add
2349        ///
2350        /// # Returns
2351        ///
2352        /// If types match, returns `Ok(())`; otherwise returns an error
2353        add_int8, Int8, i8, DataType::Int8
2354    }
2355
2356    impl_add_single_value! {
2357        /// Add an int16 value
2358        ///
2359        /// # Parameters
2360        ///
2361        /// * `value` - The int16 value to add
2362        ///
2363        /// # Returns
2364        ///
2365        /// If types match, returns `Ok(())`; otherwise returns an error
2366        add_int16, Int16, i16, DataType::Int16
2367    }
2368
2369    impl_add_single_value! {
2370        /// Add an int32 value
2371        ///
2372        /// # Parameters
2373        ///
2374        /// * `value` - The int32 value to add
2375        ///
2376        /// # Returns
2377        ///
2378        /// If types match, returns `Ok(())`; otherwise returns an error
2379        add_int32, Int32, i32, DataType::Int32
2380    }
2381
2382    impl_add_single_value! {
2383        /// Add an int64 value
2384        ///
2385        /// # Parameters
2386        ///
2387        /// * `value` - The int64 value to add
2388        ///
2389        /// # Returns
2390        ///
2391        /// If types match, returns `Ok(())`; otherwise returns an error
2392        add_int64, Int64, i64, DataType::Int64
2393    }
2394
2395    impl_add_single_value! {
2396        /// Add an int128 value
2397        ///
2398        /// # Parameters
2399        ///
2400        /// * `value` - The int128 value to add
2401        ///
2402        /// # Returns
2403        ///
2404        /// If types match, returns `Ok(())`; otherwise returns an error
2405        add_int128, Int128, i128, DataType::Int128
2406    }
2407
2408    impl_add_single_value! {
2409        /// Add a uint8 value
2410        ///
2411        /// # Parameters
2412        ///
2413        /// * `value` - The uint8 value to add
2414        ///
2415        /// # Returns
2416        ///
2417        /// If types match, returns `Ok(())`; otherwise returns an error
2418        add_uint8, UInt8, u8, DataType::UInt8
2419    }
2420
2421    impl_add_single_value! {
2422        /// Add a uint16 value
2423        ///
2424        /// # Parameters
2425        ///
2426        /// * `value` - The uint16 value to add
2427        ///
2428        /// # Returns
2429        ///
2430        /// If types match, returns `Ok(())`; otherwise returns an error
2431        add_uint16, UInt16, u16, DataType::UInt16
2432    }
2433
2434    impl_add_single_value! {
2435        /// Add a uint32 value
2436        ///
2437        /// # Parameters
2438        ///
2439        /// * `value` - The uint32 value to add
2440        ///
2441        /// # Returns
2442        ///
2443        /// If types match, returns `Ok(())`; otherwise returns an error
2444        add_uint32, UInt32, u32, DataType::UInt32
2445    }
2446
2447    impl_add_single_value! {
2448        /// Add a uint64 value
2449        ///
2450        /// # Parameters
2451        ///
2452        /// * `value` - The uint64 value to add
2453        ///
2454        /// # Returns
2455        ///
2456        /// If types match, returns `Ok(())`; otherwise returns an error
2457        add_uint64, UInt64, u64, DataType::UInt64
2458    }
2459
2460    impl_add_single_value! {
2461        /// Add a uint128 value
2462        ///
2463        /// # Parameters
2464        ///
2465        /// * `value` - The uint128 value to add
2466        ///
2467        /// # Returns
2468        ///
2469        /// If types match, returns `Ok(())`; otherwise returns an error
2470        add_uint128, UInt128, u128, DataType::UInt128
2471    }
2472
2473    impl_add_single_value! {
2474        /// Add a float32 value
2475        ///
2476        /// # Parameters
2477        ///
2478        /// * `value` - The float32 value to add
2479        ///
2480        /// # Returns
2481        ///
2482        /// If types match, returns `Ok(())`; otherwise returns an error
2483        add_float32, Float32, f32, DataType::Float32
2484    }
2485
2486    impl_add_single_value! {
2487        /// Add a float64 value
2488        ///
2489        /// # Parameters
2490        ///
2491        /// * `value` - The float64 value to add
2492        ///
2493        /// # Returns
2494        ///
2495        /// If types match, returns `Ok(())`; otherwise returns an error
2496        add_float64, Float64, f64, DataType::Float64
2497    }
2498
2499    impl_add_single_value! {
2500        /// Add a string
2501        ///
2502        /// # Parameters
2503        ///
2504        /// * `value` - The string to add
2505        ///
2506        /// # Returns
2507        ///
2508        /// If types match, returns `Ok(())`; otherwise returns an error
2509        add_string, String, String, DataType::String
2510    }
2511
2512    impl_add_single_value! {
2513        /// Add a date value
2514        ///
2515        /// # Parameters
2516        ///
2517        /// * `value` - The date value to add
2518        ///
2519        /// # Returns
2520        ///
2521        /// If types match, returns `Ok(())`; otherwise returns an error
2522        add_date, Date, NaiveDate, DataType::Date
2523    }
2524
2525    impl_add_single_value! {
2526        /// Add a time value
2527        ///
2528        /// # Parameters
2529        ///
2530        /// * `value` - The time value to add
2531        ///
2532        /// # Returns
2533        ///
2534        /// If types match, returns `Ok(())`; otherwise returns an error
2535        add_time, Time, NaiveTime, DataType::Time
2536    }
2537
2538    impl_add_single_value! {
2539        /// Add a datetime value
2540        ///
2541        /// # Parameters
2542        ///
2543        /// * `value` - The datetime value to add
2544        ///
2545        /// # Returns
2546        ///
2547        /// If types match, returns `Ok(())`; otherwise returns an error
2548        add_datetime, DateTime, NaiveDateTime, DataType::DateTime
2549    }
2550
2551    impl_add_single_value! {
2552        /// Add a UTC instant value
2553        ///
2554        /// # Parameters
2555        ///
2556        /// * `value` - The UTC instant value to add
2557        ///
2558        /// # Returns
2559        ///
2560        /// If types match, returns `Ok(())`; otherwise returns an error
2561        add_instant, Instant, DateTime<Utc>, DataType::Instant
2562    }
2563
2564    impl_add_single_value! {
2565        /// Add a big integer value
2566        ///
2567        /// # Parameters
2568        ///
2569        /// * `value` - The big integer value to add
2570        ///
2571        /// # Returns
2572        ///
2573        /// If types match, returns `Ok(())`; otherwise returns an error
2574        add_biginteger, BigInteger, BigInt, DataType::BigInteger
2575    }
2576
2577    impl_add_single_value! {
2578        /// Add a big decimal value
2579        ///
2580        /// # Parameters
2581        ///
2582        /// * `value` - The big decimal value to add
2583        ///
2584        /// # Returns
2585        ///
2586        /// If types match, returns `Ok(())`; otherwise returns an error
2587        add_bigdecimal, BigDecimal, BigDecimal, DataType::BigDecimal
2588    }
2589
2590    impl_add_single_value! {
2591        /// Add an isize value
2592        add_intsize, IntSize, isize, DataType::IntSize
2593    }
2594
2595    impl_add_single_value! {
2596        /// Add a usize value
2597        add_uintsize, UIntSize, usize, DataType::UIntSize
2598    }
2599
2600    impl_add_single_value! {
2601        /// Add a Duration value
2602        add_duration, Duration, Duration, DataType::Duration
2603    }
2604
2605    impl_add_single_value! {
2606        /// Add a Url value
2607        add_url, Url, Url, DataType::Url
2608    }
2609
2610    impl_add_single_value! {
2611        /// Add a StringMap value
2612        add_string_map, StringMap, HashMap<String, String>, DataType::StringMap
2613    }
2614
2615    impl_add_single_value! {
2616        /// Add a Json value
2617        add_json, Json, serde_json::Value, DataType::Json
2618    }
2619
2620    // ========================================================================
2621    // Add multiple values operations
2622    // ========================================================================
2623
2624    impl_add_multi_values! {
2625        /// Add multiple boolean values
2626        ///
2627        /// # Parameters
2628        ///
2629        /// * `values` - The list of boolean values to add
2630        ///
2631        /// # Returns
2632        ///
2633        /// If types match, returns `Ok(())`; otherwise returns an error
2634        ///
2635        /// # Example
2636        ///
2637        /// ```rust
2638        /// use qubit_value::MultiValues;
2639        ///
2640        /// let mut values = MultiValues::Bool(vec![true]);
2641        /// values.add_bools(vec![false, true]).unwrap();
2642        /// assert_eq!(values.get_bools().unwrap(), &[true, false, true]);
2643        /// ```
2644        add_bools, Bool, bool, DataType::Bool
2645    }
2646
2647    impl_add_multi_values! {
2648        /// Add multiple character values
2649        ///
2650        /// # Parameters
2651        ///
2652        /// * `values` - The list of character values to add
2653        ///
2654        /// # Returns
2655        ///
2656        /// If types match, returns `Ok(())`; otherwise returns an error
2657        add_chars, Char, char, DataType::Char
2658    }
2659
2660    impl_add_multi_values! {
2661        /// Add multiple int8 values
2662        ///
2663        /// # Parameters
2664        ///
2665        /// * `values` - The list of int8 values to add
2666        ///
2667        /// # Returns
2668        ///
2669        /// If types match, returns `Ok(())`; otherwise returns an error
2670        add_int8s, Int8, i8, DataType::Int8
2671    }
2672
2673    impl_add_multi_values! {
2674        /// Add multiple int16 values
2675        ///
2676        /// # Parameters
2677        ///
2678        /// * `values` - The list of int16 values to add
2679        ///
2680        /// # Returns
2681        ///
2682        /// If types match, returns `Ok(())`; otherwise returns an error
2683        add_int16s, Int16, i16, DataType::Int16
2684    }
2685
2686    impl_add_multi_values! {
2687        /// Add multiple int32 values
2688        ///
2689        /// # Parameters
2690        ///
2691        /// * `values` - The list of int32 values to add
2692        ///
2693        /// # Returns
2694        ///
2695        /// If types match, returns `Ok(())`; otherwise returns an error
2696        add_int32s, Int32, i32, DataType::Int32
2697    }
2698
2699    impl_add_multi_values! {
2700        /// Add multiple int64 values
2701        ///
2702        /// # Parameters
2703        ///
2704        /// * `values` - The list of int64 values to add
2705        ///
2706        /// # Returns
2707        ///
2708        /// If types match, returns `Ok(())`; otherwise returns an error
2709        add_int64s, Int64, i64, DataType::Int64
2710    }
2711
2712    impl_add_multi_values! {
2713        /// Add multiple int128 values
2714        ///
2715        /// # Parameters
2716        ///
2717        /// * `values` - The list of int128 values to add
2718        ///
2719        /// # Returns
2720        ///
2721        /// If types match, returns `Ok(())`; otherwise returns an error
2722        add_int128s, Int128, i128, DataType::Int128
2723    }
2724
2725    impl_add_multi_values! {
2726        /// Add multiple uint8 values
2727        ///
2728        /// # Parameters
2729        ///
2730        /// * `values` - The list of uint8 values to add
2731        ///
2732        /// # Returns
2733        ///
2734        /// If types match, returns `Ok(())`; otherwise returns an error
2735        add_uint8s, UInt8, u8, DataType::UInt8
2736    }
2737
2738    impl_add_multi_values! {
2739        /// Add multiple uint16 values
2740        ///
2741        /// # Parameters
2742        ///
2743        /// * `values` - The list of uint16 values to add
2744        ///
2745        /// # Returns
2746        ///
2747        /// If types match, returns `Ok(())`; otherwise returns an error
2748        add_uint16s, UInt16, u16, DataType::UInt16
2749    }
2750
2751    impl_add_multi_values! {
2752        /// Add multiple uint32 values
2753        ///
2754        /// # Parameters
2755        ///
2756        /// * `values` - The list of uint32 values to add
2757        ///
2758        /// # Returns
2759        ///
2760        /// If types match, returns `Ok(())`; otherwise returns an error
2761        add_uint32s, UInt32, u32, DataType::UInt32
2762    }
2763
2764    impl_add_multi_values! {
2765        /// Add multiple uint64 values
2766        ///
2767        /// # Parameters
2768        ///
2769        /// * `values` - The list of uint64 values to add
2770        ///
2771        /// # Returns
2772        ///
2773        /// If types match, returns `Ok(())`; otherwise returns an error
2774        add_uint64s, UInt64, u64, DataType::UInt64
2775    }
2776
2777    impl_add_multi_values! {
2778        /// Add multiple uint128 values
2779        ///
2780        /// # Parameters
2781        ///
2782        /// * `values` - The list of uint128 values to add
2783        ///
2784        /// # Returns
2785        ///
2786        /// If types match, returns `Ok(())`; otherwise returns an error
2787        add_uint128s, UInt128, u128, DataType::UInt128
2788    }
2789
2790    impl_add_multi_values! {
2791        /// Add multiple float32 values
2792        ///
2793        /// # Parameters
2794        ///
2795        /// * `values` - The list of float32 values to add
2796        ///
2797        /// # Returns
2798        ///
2799        /// If types match, returns `Ok(())`; otherwise returns an error
2800        add_float32s, Float32, f32, DataType::Float32
2801    }
2802
2803    impl_add_multi_values! {
2804        /// Add multiple float64 values
2805        ///
2806        /// # Parameters
2807        ///
2808        /// * `values` - The list of float64 values to add
2809        ///
2810        /// # Returns
2811        ///
2812        /// If types match, returns `Ok(())`; otherwise returns an error
2813        add_float64s, Float64, f64, DataType::Float64
2814    }
2815
2816    impl_add_multi_values! {
2817        /// Add multiple string values
2818        ///
2819        /// # Parameters
2820        ///
2821        /// * `values` - The list of string values to add
2822        ///
2823        /// # Returns
2824        ///
2825        /// If types match, returns `Ok(())`; otherwise returns an error
2826        ///
2827        /// # Example
2828        ///
2829        /// ```rust
2830        /// use qubit_value::MultiValues;
2831        ///
2832        /// let mut values = MultiValues::String(vec!["hello".to_string()]);
2833        /// values.add_strings(vec!["world".to_string(), "rust".to_string()]).unwrap();
2834        /// assert_eq!(values.get_strings().unwrap(), &["hello", "world", "rust"]);
2835        /// ```
2836        add_strings, String, String, DataType::String
2837    }
2838
2839    impl_add_multi_values! {
2840        /// Add multiple date values
2841        ///
2842        /// # Parameters
2843        ///
2844        /// * `values` - The list of date values to add
2845        ///
2846        /// # Returns
2847        ///
2848        /// If types match, returns `Ok(())`; otherwise returns an error
2849        add_dates, Date, NaiveDate, DataType::Date
2850    }
2851
2852    impl_add_multi_values! {
2853        /// Add multiple time values
2854        ///
2855        /// # Parameters
2856        ///
2857        /// * `values` - The list of time values to add
2858        ///
2859        /// # Returns
2860        ///
2861        /// If types match, returns `Ok(())`; otherwise returns an error
2862        add_times, Time, NaiveTime, DataType::Time
2863    }
2864
2865    impl_add_multi_values! {
2866        /// Add multiple datetime values
2867        ///
2868        /// # Parameters
2869        ///
2870        /// * `values` - The list of datetime values to add
2871        ///
2872        /// # Returns
2873        ///
2874        /// If types match, returns `Ok(())`; otherwise returns an error
2875        add_datetimes, DateTime, NaiveDateTime, DataType::DateTime
2876    }
2877
2878    impl_add_multi_values! {
2879        /// Add multiple UTC instant values
2880        ///
2881        /// # Parameters
2882        ///
2883        /// * `values` - The list of UTC instant values to add
2884        ///
2885        /// # Returns
2886        ///
2887        /// If types match, returns `Ok(())`; otherwise returns an error
2888        add_instants, Instant, DateTime<Utc>, DataType::Instant
2889    }
2890
2891    impl_add_multi_values! {
2892        /// Add multiple big integer values
2893        ///
2894        /// # Parameters
2895        ///
2896        /// * `values` - The list of big integer values to add
2897        ///
2898        /// # Returns
2899        ///
2900        /// If types match, returns `Ok(())`; otherwise returns an error
2901        add_bigintegers, BigInteger, BigInt, DataType::BigInteger
2902    }
2903
2904    impl_add_multi_values! {
2905        /// Add multiple big decimal values
2906        ///
2907        /// # Parameters
2908        ///
2909        /// * `values` - The list of big decimal values to add
2910        ///
2911        /// # Returns
2912        ///
2913        /// If types match, returns `Ok(())`; otherwise returns an error
2914        add_bigdecimals, BigDecimal, BigDecimal, DataType::BigDecimal
2915    }
2916
2917    impl_add_multi_values! {
2918        /// Add multiple isize values
2919        add_intsizes, IntSize, isize, DataType::IntSize
2920    }
2921
2922    impl_add_multi_values! {
2923        /// Add multiple usize values
2924        add_uintsizes, UIntSize, usize, DataType::UIntSize
2925    }
2926
2927    impl_add_multi_values! {
2928        /// Add multiple Duration values
2929        add_durations, Duration, Duration, DataType::Duration
2930    }
2931
2932    impl_add_multi_values! {
2933        /// Add multiple Url values
2934        add_urls, Url, Url, DataType::Url
2935    }
2936
2937    impl_add_multi_values! {
2938        /// Add multiple StringMap values
2939        add_string_maps, StringMap, HashMap<String, String>, DataType::StringMap
2940    }
2941
2942    impl_add_multi_values! {
2943        /// Add multiple Json values
2944        add_jsons, Json, serde_json::Value, DataType::Json
2945    }
2946
2947    // ========================================================================
2948    // Add multiple values via slice operations
2949    // ========================================================================
2950
2951    impl_add_multi_values_slice! {
2952        /// Add multiple boolean values via slice
2953        ///
2954        /// # Parameters
2955        ///
2956        /// * `values` - The boolean value slice to add
2957        ///
2958        /// # Returns
2959        ///
2960        /// If types match, returns `Ok(())`; otherwise returns an error
2961        add_bools_slice, Bool, bool, DataType::Bool
2962    }
2963
2964    impl_add_multi_values_slice! {
2965        /// Add multiple character values via slice
2966        ///
2967        /// # Parameters
2968        ///
2969        /// * `values` - The character value slice to add
2970        ///
2971        /// # Returns
2972        ///
2973        /// If types match, returns `Ok(())`; otherwise returns an error
2974        add_chars_slice, Char, char, DataType::Char
2975    }
2976
2977    impl_add_multi_values_slice! {
2978        /// Add multiple int8 values via slice
2979        ///
2980        /// # Parameters
2981        ///
2982        /// * `values` - The int8 value slice to add
2983        ///
2984        /// # Returns
2985        ///
2986        /// If types match, returns `Ok(())`; otherwise returns an error
2987        add_int8s_slice, Int8, i8, DataType::Int8
2988    }
2989
2990    impl_add_multi_values_slice! {
2991        /// Add multiple int16 values via slice
2992        ///
2993        /// # Parameters
2994        ///
2995        /// * `values` - The int16 value slice to add
2996        ///
2997        /// # Returns
2998        ///
2999        /// If types match, returns `Ok(())`; otherwise returns an error
3000        add_int16s_slice, Int16, i16, DataType::Int16
3001    }
3002
3003    impl_add_multi_values_slice! {
3004        /// Add multiple int32 values via slice
3005        ///
3006        /// # Parameters
3007        ///
3008        /// * `values` - The int32 value slice to add
3009        ///
3010        /// # Returns
3011        ///
3012        /// If types match, returns `Ok(())`; otherwise returns an error
3013        add_int32s_slice, Int32, i32, DataType::Int32
3014    }
3015
3016    impl_add_multi_values_slice! {
3017        /// Add multiple int64 values via slice
3018        ///
3019        /// # Parameters
3020        ///
3021        /// * `values` - The int64 value slice to add
3022        ///
3023        /// # Returns
3024        ///
3025        /// If types match, returns `Ok(())`; otherwise returns an error
3026        add_int64s_slice, Int64, i64, DataType::Int64
3027    }
3028
3029    impl_add_multi_values_slice! {
3030        /// Add multiple int128 values via slice
3031        ///
3032        /// # Parameters
3033        ///
3034        /// * `values` - The int128 value slice to add
3035        ///
3036        /// # Returns
3037        ///
3038        /// If types match, returns `Ok(())`; otherwise returns an error
3039        add_int128s_slice, Int128, i128, DataType::Int128
3040    }
3041
3042    impl_add_multi_values_slice! {
3043        /// Add multiple uint8 values via slice
3044        ///
3045        /// # Parameters
3046        ///
3047        /// * `values` - The uint8 value slice to add
3048        ///
3049        /// # Returns
3050        ///
3051        /// If types match, returns `Ok(())`; otherwise returns an error
3052        add_uint8s_slice, UInt8, u8, DataType::UInt8
3053    }
3054
3055    impl_add_multi_values_slice! {
3056        /// Add multiple uint16 values via slice
3057        ///
3058        /// # Parameters
3059        ///
3060        /// * `values` - The uint16 value slice to add
3061        ///
3062        /// # Returns
3063        ///
3064        /// If types match, returns `Ok(())`; otherwise returns an error
3065        add_uint16s_slice, UInt16, u16, DataType::UInt16
3066    }
3067
3068    impl_add_multi_values_slice! {
3069        /// Add multiple uint32 values via slice
3070        ///
3071        /// # Parameters
3072        ///
3073        /// * `values` - The uint32 value slice to add
3074        ///
3075        /// # Returns
3076        ///
3077        /// If types match, returns `Ok(())`; otherwise returns an error
3078        add_uint32s_slice, UInt32, u32, DataType::UInt32
3079    }
3080
3081    impl_add_multi_values_slice! {
3082        /// Add multiple uint64 values via slice
3083        ///
3084        /// # Parameters
3085        ///
3086        /// * `values` - The uint64 value slice to add
3087        ///
3088        /// # Returns
3089        ///
3090        /// If types match, returns `Ok(())`; otherwise returns an error
3091        add_uint64s_slice, UInt64, u64, DataType::UInt64
3092    }
3093
3094    impl_add_multi_values_slice! {
3095        /// Add multiple uint128 values via slice
3096        ///
3097        /// # Parameters
3098        ///
3099        /// * `values` - The uint128 value slice to add
3100        ///
3101        /// # Returns
3102        ///
3103        /// If types match, returns `Ok(())`; otherwise returns an error
3104        add_uint128s_slice, UInt128, u128, DataType::UInt128
3105    }
3106
3107    impl_add_multi_values_slice! {
3108        /// Add multiple float32 values via slice
3109        ///
3110        /// # Parameters
3111        ///
3112        /// * `values` - The float32 value slice to add
3113        ///
3114        /// # Returns
3115        ///
3116        /// If types match, returns `Ok(())`; otherwise returns an error
3117        add_float32s_slice, Float32, f32, DataType::Float32
3118    }
3119
3120    impl_add_multi_values_slice! {
3121        /// Add multiple float64 values via slice
3122        ///
3123        /// # Parameters
3124        ///
3125        /// * `values` - The float64 value slice to add
3126        ///
3127        /// # Returns
3128        ///
3129        /// If types match, returns `Ok(())`; otherwise returns an error
3130        add_float64s_slice, Float64, f64, DataType::Float64
3131    }
3132
3133    impl_add_multi_values_slice! {
3134        /// Add multiple strings via slice
3135        ///
3136        /// # Parameters
3137        ///
3138        /// * `values` - The string slice to add
3139        ///
3140        /// # Returns
3141        ///
3142        /// If types match, returns `Ok(())`; otherwise returns an error
3143        add_strings_slice, String, String, DataType::String
3144    }
3145
3146    impl_add_multi_values_slice! {
3147        /// Add multiple date values via slice
3148        ///
3149        /// # Parameters
3150        ///
3151        /// * `values` - The date value slice to add
3152        ///
3153        /// # Returns
3154        ///
3155        /// If types match, returns `Ok(())`; otherwise returns an error
3156        add_dates_slice, Date, NaiveDate, DataType::Date
3157    }
3158
3159    impl_add_multi_values_slice! {
3160        /// Add multiple time values via slice
3161        ///
3162        /// # Parameters
3163        ///
3164        /// * `values` - The time value slice to add
3165        ///
3166        /// # Returns
3167        ///
3168        /// If types match, returns `Ok(())`; otherwise returns an error
3169        add_times_slice, Time, NaiveTime, DataType::Time
3170    }
3171
3172    impl_add_multi_values_slice! {
3173        /// Add multiple datetime values via slice
3174        ///
3175        /// # Parameters
3176        ///
3177        /// * `values` - The datetime value slice to add
3178        ///
3179        /// # Returns
3180        ///
3181        /// If types match, returns `Ok(())`; otherwise returns an error
3182        add_datetimes_slice, DateTime, NaiveDateTime, DataType::DateTime
3183    }
3184
3185    impl_add_multi_values_slice! {
3186        /// Add multiple UTC instant values via slice
3187        ///
3188        /// # Parameters
3189        ///
3190        /// * `values` - The UTC instant value slice to add
3191        ///
3192        /// # Returns
3193        ///
3194        /// If types match, returns `Ok(())`; otherwise returns an error
3195        add_instants_slice, Instant, DateTime<Utc>, DataType::Instant
3196    }
3197
3198    impl_add_multi_values_slice! {
3199        /// Add multiple big integer values via slice
3200        ///
3201        /// # Parameters
3202        ///
3203        /// * `values` - The big integer value slice to add
3204        ///
3205        /// # Returns
3206        ///
3207        /// If types match, returns `Ok(())`; otherwise returns an error
3208        add_bigintegers_slice, BigInteger, BigInt, DataType::BigInteger
3209    }
3210
3211    impl_add_multi_values_slice! {
3212        /// Add multiple big decimal values via slice
3213        ///
3214        /// # Parameters
3215        ///
3216        /// * `values` - The big decimal value slice to add
3217        ///
3218        /// # Returns
3219        ///
3220        /// If types match, returns `Ok(())`; otherwise returns an error
3221        add_bigdecimals_slice, BigDecimal, BigDecimal, DataType::BigDecimal
3222    }
3223
3224    impl_add_multi_values_slice! {
3225        /// Add multiple isize values via slice
3226        add_intsizes_slice, IntSize, isize, DataType::IntSize
3227    }
3228
3229    impl_add_multi_values_slice! {
3230        /// Add multiple usize values via slice
3231        add_uintsizes_slice, UIntSize, usize, DataType::UIntSize
3232    }
3233
3234    impl_add_multi_values_slice! {
3235        /// Add multiple Duration values via slice
3236        add_durations_slice, Duration, Duration, DataType::Duration
3237    }
3238
3239    impl_add_multi_values_slice! {
3240        /// Add multiple Url values via slice
3241        add_urls_slice, Url, Url, DataType::Url
3242    }
3243
3244    impl_add_multi_values_slice! {
3245        /// Add multiple StringMap values via slice
3246        add_string_maps_slice, StringMap, HashMap<String, String>, DataType::StringMap
3247    }
3248
3249    impl_add_multi_values_slice! {
3250        /// Add multiple Json values via slice
3251        add_jsons_slice, Json, serde_json::Value, DataType::Json
3252    }
3253
3254    /// Convert to a single [`Value`] by taking the first element.
3255    ///
3256    /// If there is no element, returns `Value::Empty(self.data_type())`.
3257    ///
3258    /// # Returns
3259    ///
3260    /// Returns the first element wrapped as [`Value`], or an empty value
3261    /// preserving the current data type.
3262    pub fn to_value(&self) -> Value {
3263        match self {
3264            MultiValues::Empty(dt) => Value::Empty(*dt),
3265            MultiValues::Bool(v) => v
3266                .first()
3267                .copied()
3268                .map(Value::Bool)
3269                .unwrap_or(Value::Empty(DataType::Bool)),
3270            MultiValues::Char(v) => v
3271                .first()
3272                .copied()
3273                .map(Value::Char)
3274                .unwrap_or(Value::Empty(DataType::Char)),
3275            MultiValues::Int8(v) => v
3276                .first()
3277                .copied()
3278                .map(Value::Int8)
3279                .unwrap_or(Value::Empty(DataType::Int8)),
3280            MultiValues::Int16(v) => v
3281                .first()
3282                .copied()
3283                .map(Value::Int16)
3284                .unwrap_or(Value::Empty(DataType::Int16)),
3285            MultiValues::Int32(v) => v
3286                .first()
3287                .copied()
3288                .map(Value::Int32)
3289                .unwrap_or(Value::Empty(DataType::Int32)),
3290            MultiValues::Int64(v) => v
3291                .first()
3292                .copied()
3293                .map(Value::Int64)
3294                .unwrap_or(Value::Empty(DataType::Int64)),
3295            MultiValues::Int128(v) => v
3296                .first()
3297                .copied()
3298                .map(Value::Int128)
3299                .unwrap_or(Value::Empty(DataType::Int128)),
3300            MultiValues::UInt8(v) => v
3301                .first()
3302                .copied()
3303                .map(Value::UInt8)
3304                .unwrap_or(Value::Empty(DataType::UInt8)),
3305            MultiValues::UInt16(v) => v
3306                .first()
3307                .copied()
3308                .map(Value::UInt16)
3309                .unwrap_or(Value::Empty(DataType::UInt16)),
3310            MultiValues::UInt32(v) => v
3311                .first()
3312                .copied()
3313                .map(Value::UInt32)
3314                .unwrap_or(Value::Empty(DataType::UInt32)),
3315            MultiValues::UInt64(v) => v
3316                .first()
3317                .copied()
3318                .map(Value::UInt64)
3319                .unwrap_or(Value::Empty(DataType::UInt64)),
3320            MultiValues::UInt128(v) => v
3321                .first()
3322                .copied()
3323                .map(Value::UInt128)
3324                .unwrap_or(Value::Empty(DataType::UInt128)),
3325            MultiValues::IntSize(v) => v
3326                .first()
3327                .copied()
3328                .map(Value::IntSize)
3329                .unwrap_or(Value::Empty(DataType::IntSize)),
3330            MultiValues::UIntSize(v) => v
3331                .first()
3332                .copied()
3333                .map(Value::UIntSize)
3334                .unwrap_or(Value::Empty(DataType::UIntSize)),
3335            MultiValues::Float32(v) => v
3336                .first()
3337                .copied()
3338                .map(Value::Float32)
3339                .unwrap_or(Value::Empty(DataType::Float32)),
3340            MultiValues::Float64(v) => v
3341                .first()
3342                .copied()
3343                .map(Value::Float64)
3344                .unwrap_or(Value::Empty(DataType::Float64)),
3345            MultiValues::BigInteger(v) => v
3346                .first()
3347                .cloned()
3348                .map(Value::BigInteger)
3349                .unwrap_or(Value::Empty(DataType::BigInteger)),
3350            MultiValues::BigDecimal(v) => v
3351                .first()
3352                .cloned()
3353                .map(Value::BigDecimal)
3354                .unwrap_or(Value::Empty(DataType::BigDecimal)),
3355            MultiValues::String(v) => v
3356                .first()
3357                .cloned()
3358                .map(Value::String)
3359                .unwrap_or(Value::Empty(DataType::String)),
3360            MultiValues::Date(v) => v
3361                .first()
3362                .copied()
3363                .map(Value::Date)
3364                .unwrap_or(Value::Empty(DataType::Date)),
3365            MultiValues::Time(v) => v
3366                .first()
3367                .copied()
3368                .map(Value::Time)
3369                .unwrap_or(Value::Empty(DataType::Time)),
3370            MultiValues::DateTime(v) => v
3371                .first()
3372                .copied()
3373                .map(Value::DateTime)
3374                .unwrap_or(Value::Empty(DataType::DateTime)),
3375            MultiValues::Instant(v) => v
3376                .first()
3377                .copied()
3378                .map(Value::Instant)
3379                .unwrap_or(Value::Empty(DataType::Instant)),
3380            MultiValues::Duration(v) => v
3381                .first()
3382                .copied()
3383                .map(Value::Duration)
3384                .unwrap_or(Value::Empty(DataType::Duration)),
3385            MultiValues::Url(v) => v
3386                .first()
3387                .cloned()
3388                .map(Value::Url)
3389                .unwrap_or(Value::Empty(DataType::Url)),
3390            MultiValues::StringMap(v) => v
3391                .first()
3392                .cloned()
3393                .map(Value::StringMap)
3394                .unwrap_or(Value::Empty(DataType::StringMap)),
3395            MultiValues::Json(v) => v
3396                .first()
3397                .cloned()
3398                .map(Value::Json)
3399                .unwrap_or(Value::Empty(DataType::Json)),
3400        }
3401    }
3402
3403    /// Merge another multiple values
3404    ///
3405    /// Append all values from another multiple values to the current multiple values
3406    ///
3407    /// # Parameters
3408    ///
3409    /// * `other` - The multiple values to merge
3410    ///
3411    /// # Returns
3412    ///
3413    /// If types match, returns `Ok(())`; otherwise returns an error
3414    ///
3415    /// # Example
3416    ///
3417    /// ```rust
3418    /// use qubit_value::MultiValues;
3419    ///
3420    /// let mut a = MultiValues::Int32(vec![1, 2]);
3421    /// let b = MultiValues::Int32(vec![3, 4]);
3422    /// a.merge(&b).unwrap();
3423    /// assert_eq!(a.get_int32s().unwrap(), &[1, 2, 3, 4]);
3424    /// ```
3425    pub fn merge(&mut self, other: &MultiValues) -> ValueResult<()> {
3426        if self.data_type() != other.data_type() {
3427            return Err(ValueError::TypeMismatch {
3428                expected: self.data_type(),
3429                actual: other.data_type(),
3430            });
3431        }
3432
3433        match (self, other) {
3434            (MultiValues::Bool(v), MultiValues::Bool(o)) => v.extend_from_slice(o),
3435            (MultiValues::Char(v), MultiValues::Char(o)) => v.extend_from_slice(o),
3436            (MultiValues::Int8(v), MultiValues::Int8(o)) => v.extend_from_slice(o),
3437            (MultiValues::Int16(v), MultiValues::Int16(o)) => v.extend_from_slice(o),
3438            (MultiValues::Int32(v), MultiValues::Int32(o)) => v.extend_from_slice(o),
3439            (MultiValues::Int64(v), MultiValues::Int64(o)) => v.extend_from_slice(o),
3440            (MultiValues::Int128(v), MultiValues::Int128(o)) => v.extend_from_slice(o),
3441            (MultiValues::UInt8(v), MultiValues::UInt8(o)) => v.extend_from_slice(o),
3442            (MultiValues::UInt16(v), MultiValues::UInt16(o)) => v.extend_from_slice(o),
3443            (MultiValues::UInt32(v), MultiValues::UInt32(o)) => v.extend_from_slice(o),
3444            (MultiValues::UInt64(v), MultiValues::UInt64(o)) => v.extend_from_slice(o),
3445            (MultiValues::UInt128(v), MultiValues::UInt128(o)) => v.extend_from_slice(o),
3446            (MultiValues::Float32(v), MultiValues::Float32(o)) => v.extend_from_slice(o),
3447            (MultiValues::Float64(v), MultiValues::Float64(o)) => v.extend_from_slice(o),
3448            (MultiValues::String(v), MultiValues::String(o)) => v.extend_from_slice(o),
3449            (MultiValues::Date(v), MultiValues::Date(o)) => v.extend_from_slice(o),
3450            (MultiValues::Time(v), MultiValues::Time(o)) => v.extend_from_slice(o),
3451            (MultiValues::DateTime(v), MultiValues::DateTime(o)) => v.extend_from_slice(o),
3452            (MultiValues::Instant(v), MultiValues::Instant(o)) => v.extend_from_slice(o),
3453            (MultiValues::BigInteger(v), MultiValues::BigInteger(o)) => v.extend_from_slice(o),
3454            (MultiValues::BigDecimal(v), MultiValues::BigDecimal(o)) => v.extend_from_slice(o),
3455            (MultiValues::IntSize(v), MultiValues::IntSize(o)) => v.extend_from_slice(o),
3456            (MultiValues::UIntSize(v), MultiValues::UIntSize(o)) => v.extend_from_slice(o),
3457            (MultiValues::Duration(v), MultiValues::Duration(o)) => v.extend_from_slice(o),
3458            (MultiValues::Url(v), MultiValues::Url(o)) => v.extend_from_slice(o),
3459            (MultiValues::StringMap(v), MultiValues::StringMap(o)) => v.extend(o.iter().cloned()),
3460            (MultiValues::Json(v), MultiValues::Json(o)) => v.extend(o.iter().cloned()),
3461            (slot @ MultiValues::Empty(_), other_values) => *slot = other_values.clone(),
3462            _ => unreachable!(),
3463        }
3464
3465        Ok(())
3466    }
3467}
3468
3469impl Default for MultiValues {
3470    #[inline]
3471    fn default() -> Self {
3472        MultiValues::Empty(DataType::String)
3473    }
3474}
3475
3476impl From<Value> for MultiValues {
3477    fn from(value: Value) -> Self {
3478        match value {
3479            Value::Empty(dt) => MultiValues::Empty(dt),
3480            Value::Bool(v) => MultiValues::Bool(vec![v]),
3481            Value::Char(v) => MultiValues::Char(vec![v]),
3482            Value::Int8(v) => MultiValues::Int8(vec![v]),
3483            Value::Int16(v) => MultiValues::Int16(vec![v]),
3484            Value::Int32(v) => MultiValues::Int32(vec![v]),
3485            Value::Int64(v) => MultiValues::Int64(vec![v]),
3486            Value::Int128(v) => MultiValues::Int128(vec![v]),
3487            Value::UInt8(v) => MultiValues::UInt8(vec![v]),
3488            Value::UInt16(v) => MultiValues::UInt16(vec![v]),
3489            Value::UInt32(v) => MultiValues::UInt32(vec![v]),
3490            Value::UInt64(v) => MultiValues::UInt64(vec![v]),
3491            Value::UInt128(v) => MultiValues::UInt128(vec![v]),
3492            Value::Float32(v) => MultiValues::Float32(vec![v]),
3493            Value::Float64(v) => MultiValues::Float64(vec![v]),
3494            Value::String(v) => MultiValues::String(vec![v]),
3495            Value::Date(v) => MultiValues::Date(vec![v]),
3496            Value::Time(v) => MultiValues::Time(vec![v]),
3497            Value::DateTime(v) => MultiValues::DateTime(vec![v]),
3498            Value::Instant(v) => MultiValues::Instant(vec![v]),
3499            Value::BigInteger(v) => MultiValues::BigInteger(vec![v]),
3500            Value::BigDecimal(v) => MultiValues::BigDecimal(vec![v]),
3501            Value::IntSize(v) => MultiValues::IntSize(vec![v]),
3502            Value::UIntSize(v) => MultiValues::UIntSize(vec![v]),
3503            Value::Duration(v) => MultiValues::Duration(vec![v]),
3504            Value::Url(v) => MultiValues::Url(vec![v]),
3505            Value::StringMap(v) => MultiValues::StringMap(vec![v]),
3506            Value::Json(v) => MultiValues::Json(vec![v]),
3507        }
3508    }
3509}
3510
3511// ============================================================================
3512// Internal generic conversion traits (private, not exported, to avoid polluting
3513// the standard type namespace).
3514// ============================================================================
3515
3516/// Internal trait: used to extract multiple values from MultiValues
3517///
3518/// This trait is used for internal implementation and cross-crate usage
3519#[doc(hidden)]
3520pub trait MultiValuesGetter<T> {
3521    fn get_values(&self) -> ValueResult<Vec<T>>;
3522}
3523
3524/// Internal trait: used to extract the first value from MultiValues
3525///
3526/// This trait is used for internal implementation and cross-crate usage
3527#[doc(hidden)]
3528pub trait MultiValuesFirstGetter<T> {
3529    fn get_first_value(&self) -> ValueResult<T>;
3530}
3531
3532/// Internal trait: used to set specific types in MultiValues
3533///
3534/// This trait is used for internal implementation and cross-crate usage
3535#[doc(hidden)]
3536pub trait MultiValuesSetter<T> {
3537    fn set_values(&mut self, values: Vec<T>) -> ValueResult<()>;
3538}
3539
3540/// Internal dispatch trait: dispatches Vec<T>, &[T], T to optimal set path
3541#[doc(hidden)]
3542pub trait MultiValuesSetArg<'a> {
3543    /// Element type
3544    type Item: 'a + Clone;
3545
3546    fn apply(self, target: &mut MultiValues) -> ValueResult<()>;
3547}
3548
3549/// Internal trait: used to set specific types in MultiValues via slice
3550///
3551/// This trait is used for internal implementation and cross-crate usage
3552#[doc(hidden)]
3553pub trait MultiValuesSetterSlice<T> {
3554    fn set_values_slice(&mut self, values: &[T]) -> ValueResult<()>;
3555}
3556
3557/// Internal trait: used to set a single value in MultiValues
3558///
3559/// This trait is used for internal implementation and cross-crate usage
3560#[doc(hidden)]
3561pub trait MultiValuesSingleSetter<T> {
3562    fn set_single_value(&mut self, value: T) -> ValueResult<()>;
3563}
3564
3565/// Internal trait: used to add a single value to MultiValues
3566///
3567/// This trait is used for internal implementation and cross-crate usage
3568#[doc(hidden)]
3569pub trait MultiValuesAdder<T> {
3570    fn add_value(&mut self, value: T) -> ValueResult<()>;
3571}
3572
3573/// Internal trait: used to add multiple values to MultiValues
3574///
3575/// This trait is used for internal implementation and cross-crate usage
3576#[doc(hidden)]
3577pub trait MultiValuesMultiAdder<T> {
3578    fn add_values(&mut self, values: Vec<T>) -> ValueResult<()>;
3579}
3580
3581/// Internal dispatch trait: dispatches T / Vec<T> / &[T] to optimal add path
3582#[doc(hidden)]
3583pub trait MultiValuesAddArg<'a> {
3584    /// Element type
3585    type Item: 'a + Clone;
3586
3587    fn apply_add(self, target: &mut MultiValues) -> ValueResult<()>;
3588}
3589
3590/// Internal trait: used to append multiple values to MultiValues via slice
3591/// (calls add_[xxx]s_slice by type)
3592#[doc(hidden)]
3593pub(crate) trait MultiValuesMultiAdderSlice<T> {
3594    fn add_values_slice(&mut self, values: &[T]) -> ValueResult<()>;
3595}
3596
3597/// Internal trait: used to create MultiValues from Vec<T>
3598///
3599/// This trait is not exported in mod.rs, only used for internal implementation,
3600/// to avoid polluting the standard type namespace
3601#[doc(hidden)]
3602pub(crate) trait MultiValuesConstructor<T> {
3603    fn from_vec(values: Vec<T>) -> Self;
3604}
3605
3606// ============================================================================
3607// Internal trait implementations (simplified using macros)
3608// ============================================================================
3609
3610macro_rules! impl_multi_value_traits {
3611    ($type:ty, $variant:ident, $data_type:expr) => {
3612        impl MultiValuesGetter<$type> for MultiValues {
3613            #[inline]
3614            fn get_values(&self) -> ValueResult<Vec<$type>> {
3615                match self {
3616                    MultiValues::$variant(v) => Ok(v.clone()),
3617                    MultiValues::Empty(dt) if *dt == $data_type => Ok(Vec::new()),
3618                    _ => Err(ValueError::TypeMismatch {
3619                        expected: $data_type,
3620                        actual: self.data_type(),
3621                    }),
3622                }
3623            }
3624        }
3625
3626        impl MultiValuesFirstGetter<$type> for MultiValues {
3627            #[inline]
3628            fn get_first_value(&self) -> ValueResult<$type> {
3629                match self {
3630                    MultiValues::$variant(v) if !v.is_empty() => Ok(v[0].clone()),
3631                    MultiValues::$variant(_) => Err(ValueError::NoValue),
3632                    MultiValues::Empty(dt) if *dt == $data_type => Err(ValueError::NoValue),
3633                    _ => Err(ValueError::TypeMismatch {
3634                        expected: $data_type,
3635                        actual: self.data_type(),
3636                    }),
3637                }
3638            }
3639        }
3640
3641        impl MultiValuesSetter<$type> for MultiValues {
3642            #[inline]
3643            fn set_values(&mut self, values: Vec<$type>) -> ValueResult<()> {
3644                *self = MultiValues::$variant(values);
3645                Ok(())
3646            }
3647        }
3648
3649        // Generic From implementation for SetParam is at the top level, not
3650        // repeated here for specific types.
3651
3652        impl MultiValuesSetterSlice<$type> for MultiValues {
3653            #[inline]
3654            fn set_values_slice(&mut self, values: &[$type]) -> ValueResult<()> {
3655                // Equivalent to set_[xxx]s_slice: replace entire list with slice
3656                *self = MultiValues::$variant(values.to_vec());
3657                Ok(())
3658            }
3659        }
3660
3661        impl MultiValuesSingleSetter<$type> for MultiValues {
3662            #[inline]
3663            fn set_single_value(&mut self, value: $type) -> ValueResult<()> {
3664                *self = MultiValues::$variant(vec![value]);
3665                Ok(())
3666            }
3667        }
3668
3669        impl MultiValuesAdder<$type> for MultiValues {
3670            #[inline]
3671            fn add_value(&mut self, value: $type) -> ValueResult<()> {
3672                match self {
3673                    MultiValues::$variant(v) => {
3674                        v.push(value);
3675                        Ok(())
3676                    }
3677                    MultiValues::Empty(dt) if *dt == $data_type => {
3678                        *self = MultiValues::$variant(vec![value]);
3679                        Ok(())
3680                    }
3681                    _ => Err(ValueError::TypeMismatch {
3682                        expected: $data_type,
3683                        actual: self.data_type(),
3684                    }),
3685                }
3686            }
3687        }
3688
3689        // Three types of implementations for local dispatch trait
3690        impl<'a> MultiValuesSetArg<'a> for Vec<$type> {
3691            type Item = $type;
3692
3693            #[inline]
3694            fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
3695                <MultiValues as MultiValuesSetter<$type>>::set_values(target, self)
3696            }
3697        }
3698
3699        impl<'a> MultiValuesSetArg<'a> for &'a [$type]
3700        where
3701            $type: Clone,
3702        {
3703            type Item = $type;
3704
3705            #[inline]
3706            fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
3707                <MultiValues as MultiValuesSetterSlice<$type>>::set_values_slice(target, self)
3708            }
3709        }
3710
3711        impl<'a> MultiValuesSetArg<'a> for $type {
3712            type Item = $type;
3713
3714            #[inline]
3715            fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
3716                <MultiValues as MultiValuesSingleSetter<$type>>::set_single_value(target, self)
3717            }
3718        }
3719
3720        impl MultiValuesMultiAdder<$type> for MultiValues {
3721            #[inline]
3722            fn add_values(&mut self, values: Vec<$type>) -> ValueResult<()> {
3723                match self {
3724                    MultiValues::$variant(v) => {
3725                        v.extend(values);
3726                        Ok(())
3727                    }
3728                    MultiValues::Empty(dt) if *dt == $data_type => {
3729                        *self = MultiValues::$variant(values);
3730                        Ok(())
3731                    }
3732                    _ => Err(ValueError::TypeMismatch {
3733                        expected: $data_type,
3734                        actual: self.data_type(),
3735                    }),
3736                }
3737            }
3738        }
3739
3740        impl MultiValuesMultiAdderSlice<$type> for MultiValues {
3741            #[inline]
3742            fn add_values_slice(&mut self, values: &[$type]) -> ValueResult<()> {
3743                match self {
3744                    MultiValues::$variant(v) => {
3745                        v.extend_from_slice(values);
3746                        Ok(())
3747                    }
3748                    MultiValues::Empty(dt) if *dt == $data_type => {
3749                        *self = MultiValues::$variant(values.to_vec());
3750                        Ok(())
3751                    }
3752                    _ => Err(ValueError::TypeMismatch {
3753                        expected: $data_type,
3754                        actual: self.data_type(),
3755                    }),
3756                }
3757            }
3758        }
3759
3760        // add dispatch: T / Vec<T> / &[T]
3761        impl<'a> MultiValuesAddArg<'a> for $type {
3762            type Item = $type;
3763
3764            #[inline]
3765            fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
3766                <MultiValues as MultiValuesAdder<$type>>::add_value(target, self)
3767            }
3768        }
3769
3770        impl<'a> MultiValuesAddArg<'a> for Vec<$type> {
3771            type Item = $type;
3772
3773            #[inline]
3774            fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
3775                <MultiValues as MultiValuesMultiAdder<$type>>::add_values(target, self)
3776            }
3777        }
3778
3779        impl<'a> MultiValuesAddArg<'a> for &'a [$type]
3780        where
3781            $type: Clone,
3782        {
3783            type Item = $type;
3784
3785            #[inline]
3786            fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
3787                <MultiValues as MultiValuesMultiAdderSlice<$type>>::add_values_slice(target, self)
3788            }
3789        }
3790
3791        impl MultiValuesConstructor<$type> for MultiValues {
3792            #[inline]
3793            fn from_vec(values: Vec<$type>) -> Self {
3794                MultiValues::$variant(values)
3795            }
3796        }
3797    };
3798}
3799
3800// Implementation for Copy types
3801impl_multi_value_traits!(bool, Bool, DataType::Bool);
3802impl_multi_value_traits!(char, Char, DataType::Char);
3803impl_multi_value_traits!(i8, Int8, DataType::Int8);
3804impl_multi_value_traits!(i16, Int16, DataType::Int16);
3805impl_multi_value_traits!(i32, Int32, DataType::Int32);
3806impl_multi_value_traits!(i64, Int64, DataType::Int64);
3807impl_multi_value_traits!(i128, Int128, DataType::Int128);
3808impl_multi_value_traits!(u8, UInt8, DataType::UInt8);
3809impl_multi_value_traits!(u16, UInt16, DataType::UInt16);
3810impl_multi_value_traits!(u32, UInt32, DataType::UInt32);
3811impl_multi_value_traits!(u64, UInt64, DataType::UInt64);
3812impl_multi_value_traits!(u128, UInt128, DataType::UInt128);
3813impl_multi_value_traits!(f32, Float32, DataType::Float32);
3814impl_multi_value_traits!(f64, Float64, DataType::Float64);
3815impl_multi_value_traits!(String, String, DataType::String);
3816impl_multi_value_traits!(NaiveDate, Date, DataType::Date);
3817impl_multi_value_traits!(NaiveTime, Time, DataType::Time);
3818impl_multi_value_traits!(NaiveDateTime, DateTime, DataType::DateTime);
3819impl_multi_value_traits!(DateTime<Utc>, Instant, DataType::Instant);
3820impl_multi_value_traits!(BigInt, BigInteger, DataType::BigInteger);
3821impl_multi_value_traits!(BigDecimal, BigDecimal, DataType::BigDecimal);
3822impl_multi_value_traits!(isize, IntSize, DataType::IntSize);
3823impl_multi_value_traits!(usize, UIntSize, DataType::UIntSize);
3824impl_multi_value_traits!(Duration, Duration, DataType::Duration);
3825impl_multi_value_traits!(Url, Url, DataType::Url);
3826impl_multi_value_traits!(HashMap<String, String>, StringMap, DataType::StringMap);
3827impl_multi_value_traits!(serde_json::Value, Json, DataType::Json);
3828
3829// Convenience adaptation: &str supported as input type for String
3830impl MultiValuesSetArg<'_> for &str {
3831    type Item = String;
3832
3833    #[inline]
3834    fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
3835        <MultiValues as MultiValuesSingleSetter<String>>::set_single_value(target, self.to_string())
3836    }
3837}
3838
3839impl MultiValuesSetArg<'_> for Vec<&str> {
3840    type Item = String;
3841
3842    #[inline]
3843    fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
3844        let owned: Vec<String> = self.into_iter().map(|s| s.to_string()).collect();
3845        <MultiValues as MultiValuesSetter<String>>::set_values(target, owned)
3846    }
3847}
3848
3849impl<'b> MultiValuesSetArg<'_> for &'b [&'b str] {
3850    type Item = String;
3851
3852    #[inline]
3853    fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
3854        let owned: Vec<String> = self.iter().map(|s| (*s).to_string()).collect();
3855        <MultiValues as MultiValuesSetter<String>>::set_values(target, owned)
3856    }
3857}
3858
3859impl MultiValuesAddArg<'_> for &str {
3860    type Item = String;
3861
3862    #[inline]
3863    fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
3864        <MultiValues as MultiValuesAdder<String>>::add_value(target, self.to_string())
3865    }
3866}
3867
3868impl MultiValuesAddArg<'_> for Vec<&str> {
3869    type Item = String;
3870
3871    #[inline]
3872    fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
3873        let owned: Vec<String> = self.into_iter().map(|s| s.to_string()).collect();
3874        <MultiValues as MultiValuesMultiAdder<String>>::add_values(target, owned)
3875    }
3876}
3877
3878impl<'b> MultiValuesAddArg<'_> for &'b [&'b str] {
3879    type Item = String;
3880
3881    #[inline]
3882    fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
3883        let owned: Vec<String> = self.iter().map(|s| (*s).to_string()).collect();
3884        <MultiValues as MultiValuesMultiAdder<String>>::add_values(target, owned)
3885    }
3886}