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