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