• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

qubit-ltd / rust-value / aaa3f070-7513-4cfb-b87a-4ff0eacf006a

09 Apr 2026 01:59PM UTC coverage: 99.163%. Remained the same
aaa3f070-7513-4cfb-b87a-4ff0eacf006a

push

circleci

Haixing-Hu
chore: remove .circleci documentation and fix rustdoc wrap indent

- Delete obsolete CircleCI setup and notes markdown under .circleci/
- Align wrapped line in MultiValues::set rustdoc Parameters list

1066 of 1075 relevant lines covered (99.16%)

37.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.8
/src/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

19
use bigdecimal::BigDecimal;
20
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
21
use num_bigint::BigInt;
22
use serde::{Deserialize, Serialize};
23
use std::collections::HashMap;
24
use std::time::Duration;
25
use url::Url;
26

27
use qubit_common::lang::DataType;
28

29
use super::error::{ValueError, ValueResult};
30
use super::value::Value;
31

32
/// Multiple values container
33
///
34
/// Uses an enum to represent multiple values of different types, providing
35
/// type-safe storage and access for multiple values.
36
///
37
/// # Features
38
///
39
/// - Supports collections of multiple basic data types.
40
/// - Provides two sets of APIs for type checking and type conversion.
41
/// - Supports unified access to single and multiple values.
42
/// - Automatic memory management.
43
///
44
/// # Example
45
///
46
/// ```rust,ignore
47
/// use common_rs::util::value::MultiValues;
48
///
49
/// // Create integer multiple values
50
/// let mut values = MultiValues::Int32(vec![1, 2, 3]);
51
/// assert_eq!(values.count(), 3);
52
/// assert_eq!(values.get_first_int32().unwrap(), 1);
53
///
54
/// // Get all values
55
/// let all = values.get_int32s().unwrap();
56
/// assert_eq!(all, &[1, 2, 3]);
57
///
58
/// // Use generic method to add value
59
/// values.add(4).unwrap();
60
/// assert_eq!(values.count(), 4);
61
/// ```
62
///
63
/// # Author
64
///
65
/// Haixing Hu
66
///
67
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
68
pub enum MultiValues {
69
    /// Empty value (has type but no values)
70
    Empty(DataType),
71
    /// Boolean value list
72
    Bool(Vec<bool>),
73
    /// Character value list
74
    Char(Vec<char>),
75
    /// i8 list
76
    Int8(Vec<i8>),
77
    /// i16 list
78
    Int16(Vec<i16>),
79
    /// i32 list
80
    Int32(Vec<i32>),
81
    /// i64 list
82
    Int64(Vec<i64>),
83
    /// i128 list
84
    Int128(Vec<i128>),
85
    /// u8 list
86
    UInt8(Vec<u8>),
87
    /// u16 list
88
    UInt16(Vec<u16>),
89
    /// u32 list
90
    UInt32(Vec<u32>),
91
    /// u64 list
92
    UInt64(Vec<u64>),
93
    /// u128 list
94
    UInt128(Vec<u128>),
95
    /// isize list
96
    IntSize(Vec<isize>),
97
    /// usize list
98
    UIntSize(Vec<usize>),
99
    /// f32 list
100
    Float32(Vec<f32>),
101
    /// f64 list
102
    Float64(Vec<f64>),
103
    /// Big integer list
104
    BigInteger(Vec<BigInt>),
105
    /// Big decimal list
106
    BigDecimal(Vec<BigDecimal>),
107
    /// String list
108
    String(Vec<String>),
109
    /// Date list
110
    Date(Vec<NaiveDate>),
111
    /// Time list
112
    Time(Vec<NaiveTime>),
113
    /// DateTime list
114
    DateTime(Vec<NaiveDateTime>),
115
    /// UTC instant list
116
    Instant(Vec<DateTime<Utc>>),
117
    /// Duration list
118
    Duration(Vec<Duration>),
119
    /// Url list
120
    Url(Vec<Url>),
121
    /// StringMap list
122
    StringMap(Vec<HashMap<String, String>>),
123
    /// Json list
124
    Json(Vec<serde_json::Value>),
125
}
126

127
// ============================================================================
128
// Getter method generation macros
129
// ============================================================================
130

131
/// Unified multiple values getter generation macro
132
///
133
/// Generates `get_[xxx]s` methods for `MultiValues`, returning a reference to
134
/// value slices.
135
///
136
/// # Documentation Comment Support
137
///
138
/// The macro automatically extracts preceding documentation comments, so you
139
/// can add `///` comments before macro invocations.
140
///
141
/// # Author
142
///
143
/// Haixing Hu
144
///
145
macro_rules! impl_get_multi_values {
146
    // Simple type: return slice reference
147
    ($(#[$attr:meta])* slice: $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
148
        $(#[$attr])*
149
        pub fn $method(&self) -> ValueResult<&[$type]> {
404✔
150
            match self {
404✔
151
                MultiValues::$variant(v) => Ok(v),
342✔
152
                MultiValues::Empty(_) => Ok(&[]),
10✔
153
                _ => Err(ValueError::TypeMismatch {
52✔
154
                    expected: $data_type,
52✔
155
                    actual: self.data_type(),
52✔
156
                }),
52✔
157
            }
158
        }
404✔
159
    };
160

161
    // Complex type: return Vec reference (e.g., Vec<String>, Vec<Vec<u8>>)
162
    ($(#[$attr:meta])* vec: $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
163
        $(#[$attr])*
164
        pub fn $method(&self) -> ValueResult<&[$type]> {
112✔
165
            match self {
112✔
166
                MultiValues::$variant(v) => Ok(v.as_slice()),
92✔
167
                MultiValues::Empty(_) => Ok(&[]),
2✔
168
                _ => Err(ValueError::TypeMismatch {
18✔
169
                    expected: $data_type,
18✔
170
                    actual: self.data_type(),
18✔
171
                }),
18✔
172
            }
173
        }
112✔
174
    };
175
}
176

177
/// Unified multiple values get_first method generation macro
178
///
179
/// Generates `get_first_[xxx]` methods for `MultiValues`, used to get the first
180
/// value.
181
///
182
/// # Documentation Comment Support
183
///
184
/// The macro automatically extracts preceding documentation comments, so you
185
/// can add `///` comments before macro invocations.
186
///
187
/// # Author
188
///
189
/// Haixing Hu
190
///
191
macro_rules! impl_get_first_value {
192
    // Copy type: directly return value
193
    ($(#[$attr:meta])* copy: $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
194
        $(#[$attr])*
195
        pub fn $method(&self) -> ValueResult<$type> {
230✔
196
            match self {
146✔
197
                MultiValues::$variant(v) if !v.is_empty() => Ok(v[0]),
146✔
198
                MultiValues::$variant(_) | MultiValues::Empty(_) => Err(ValueError::NoValue),
62✔
199
                _ => Err(ValueError::TypeMismatch {
46✔
200
                    expected: $data_type,
46✔
201
                    actual: self.data_type(),
46✔
202
                }),
46✔
203
            }
204
        }
230✔
205
    };
206

207
    // Reference type: return reference
208
    ($(#[$attr:meta])* ref: $method:ident, $variant:ident, $ret_type:ty, $data_type:expr, $conversion:expr) => {
209
        $(#[$attr])*
210
        pub fn $method(&self) -> ValueResult<$ret_type> {
66✔
211
            match self {
50✔
212
                MultiValues::$variant(v) if !v.is_empty() => {
50✔
213
                    let conv_fn: fn(&_) -> $ret_type = $conversion;
48✔
214
                    Ok(conv_fn(&v[0]))
48✔
215
                },
216
                MultiValues::$variant(_) | MultiValues::Empty(_) => Err(ValueError::NoValue),
8✔
217
                _ => Err(ValueError::TypeMismatch {
10✔
218
                    expected: $data_type,
10✔
219
                    actual: self.data_type(),
10✔
220
                }),
10✔
221
            }
222
        }
66✔
223
    };
224
}
225

226
/// Unified multiple values add method generation macro
227
///
228
/// Generates `add_[xxx]` methods for `MultiValues`, used to add a single value.
229
///
230
/// # Documentation Comment Support
231
///
232
/// The macro automatically extracts preceding documentation comments, so you
233
/// can add `///` comments before macro invocations.
234
///
235
/// # Author
236
///
237
/// Haixing Hu
238
///
239
macro_rules! impl_add_single_value {
240
    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
241
        $(#[$attr])*
242
        pub fn $method(&mut self, value: $type) -> ValueResult<()> {
254✔
243
            match self {
114✔
244
                MultiValues::$variant(v) => {
54✔
245
                    v.push(value);
54✔
246
                    Ok(())
54✔
247
                }
248
                MultiValues::Empty(dt) if *dt == $data_type => {
114✔
249
                    *self = MultiValues::$variant(vec![value]);
68✔
250
                    Ok(())
68✔
251
                }
252
                _ => Err(ValueError::TypeMismatch {
132✔
253
                    expected: $data_type,
132✔
254
                    actual: self.data_type(),
132✔
255
                }),
132✔
256
            }
257
        }
254✔
258
    };
259
}
260

261
/// Unified multiple values add multiple method generation macro
262
///
263
/// Generates `add_[xxx]s` methods for `MultiValues`, used to add multiple values.
264
///
265
/// # Documentation Comment Support
266
///
267
/// The macro automatically extracts preceding documentation comments, so you
268
/// can add `///` comments before macro invocations.
269
///
270
/// # Author
271
///
272
/// Haixing Hu
273
///
274
macro_rules! impl_add_multi_values {
275
    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
276
        $(#[$attr])*
277
        pub fn $method(&mut self, values: Vec<$type>) -> ValueResult<()> {
176✔
278
            match self {
54✔
279
                MultiValues::$variant(v) => {
64✔
280
                    v.extend(values);
64✔
281
                    Ok(())
64✔
282
                }
283
                MultiValues::Empty(dt) if *dt == $data_type => {
54✔
284
                    *self = MultiValues::$variant(values);
52✔
285
                    Ok(())
52✔
286
                }
287
                _ => Err(ValueError::TypeMismatch {
60✔
288
                    expected: $data_type,
60✔
289
                    actual: self.data_type(),
60✔
290
                }),
60✔
291
            }
292
        }
176✔
293
    };
294
}
295

296
/// Unified multiple values add from slice method generation macro
297
///
298
/// Generates `add_[xxx]s_slice` methods for `MultiValues`, used to append
299
/// multiple values at once from a slice.
300
///
301
/// # Author
302
///
303
/// Haixing Hu
304
///
305
macro_rules! impl_add_multi_values_slice {
306
    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
307
        $(#[$attr])*
308
        pub fn $method(&mut self, values: &[$type]) -> ValueResult<()> {
160✔
309
            match self {
70✔
310
                MultiValues::$variant(v) => {
36✔
311
                    v.extend_from_slice(values);
36✔
312
                    Ok(())
36✔
313
                }
314
                MultiValues::Empty(dt) if *dt == $data_type => {
70✔
315
                    *self = MultiValues::$variant(values.to_vec());
70✔
316
                    Ok(())
70✔
317
                }
318
                _ => Err(ValueError::TypeMismatch {
54✔
319
                    expected: $data_type,
54✔
320
                    actual: self.data_type(),
54✔
321
                }),
54✔
322
            }
323
        }
160✔
324
    };
325
}
326

327
/// Unified multiple values single value set method generation macro
328
///
329
/// Generates `set_[xxx]` methods for `MultiValues`, used to set a single value
330
/// (replacing the entire list).
331
///
332
/// # Documentation Comment Support
333
///
334
/// The macro automatically extracts preceding documentation comments, so you
335
/// can add `///` comments before macro invocations.
336
///
337
/// # Author
338
///
339
/// Haixing Hu
340
///
341
macro_rules! impl_set_single_value {
342
    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
343
        $(#[$attr])*
344
        pub fn $method(&mut self, value: $type) -> ValueResult<()> {
74✔
345
            *self = MultiValues::$variant(vec![value]);
74✔
346
            Ok(())
74✔
347
        }
74✔
348
    };
349
}
350

351
/// Unified multiple values set method generation macro
352
///
353
/// Generates `set_[xxx]s` methods for `MultiValues`, used to set the entire
354
/// value list.
355
///
356
/// # Documentation Comment Support
357
///
358
/// The macro automatically extracts preceding documentation comments, so you
359
/// can add `///` comments before macro invocations.
360
///
361
/// # Author
362
///
363
/// Haixing Hu
364
///
365
macro_rules! impl_set_multi_values {
366
    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
367
        $(#[$attr])*
368
        pub fn $method(&mut self, values: Vec<$type>) -> ValueResult<()> {
66✔
369
            *self = MultiValues::$variant(values);
66✔
370
            Ok(())
66✔
371
        }
66✔
372
    };
373
}
374

375
/// Unified multiple values set (slice) method generation macro
376
///
377
/// Generates `set_[xxx]s_slice` methods for `MultiValues`, used to set the
378
/// entire value list from a slice.
379
///
380
/// This method directly replaces the internally stored list without type
381
/// matching checks, behaving consistently with `set_[xxx]s`.
382
///
383
/// # Documentation Comment Support
384
///
385
/// The macro automatically extracts preceding documentation comments, so you
386
/// can add `///` comments before macro invocations.
387
///
388
/// # Author
389
///
390
/// Haixing Hu
391
///
392
macro_rules! impl_set_multi_values_slice {
393
    ($(#[$attr:meta])* $method:ident, $variant:ident, $type:ty, $data_type:expr) => {
394
        $(#[$attr])*
395
        pub fn $method(&mut self, values: &[$type]) -> ValueResult<()> {
26✔
396
            *self = MultiValues::$variant(values.to_vec());
26✔
397
            Ok(())
26✔
398
        }
26✔
399
    };
400
}
401

402
impl MultiValues {
403
    /// Generic constructor method
404
    ///
405
    /// Creates `MultiValues` from `Vec<T>`, avoiding direct use of enum
406
    /// variants.
407
    ///
408
    /// # Type Parameters
409
    ///
410
    /// * `T` - Element type
411
    ///
412
    /// # Returns
413
    ///
414
    /// Returns `MultiValues` wrapping the given value list
415
    ///
416
    /// # Example
417
    ///
418
    /// ```rust,ignore
419
    /// use crate::util::value::MultiValues;
420
    ///
421
    /// // Basic types
422
    /// let mv = MultiValues::new(vec![1, 2, 3]);
423
    /// assert_eq!(mv.count(), 3);
424
    ///
425
    /// // Strings
426
    /// let mv = MultiValues::new(vec!["a".to_string(), "b".to_string()]);
427
    /// assert_eq!(mv.count(), 2);
428
    /// ```
429
    pub fn new<T>(values: Vec<T>) -> Self
16✔
430
    where
16✔
431
        Self: MultiValuesConstructor<T>,
16✔
432
    {
433
        <Self as MultiValuesConstructor<T>>::from_vec(values)
16✔
434
    }
16✔
435

436
    /// Generic getter method for multiple values
437
    ///
438
    /// Automatically selects the correct getter method based on the target
439
    /// type, performing strict type checking.
440
    ///
441
    /// # Type Parameters
442
    ///
443
    /// * `T` - The target element type to retrieve.
444
    ///
445
    /// # Returns
446
    ///
447
    /// If types match, returns the list of values; otherwise returns an error.
448
    ///
449
    /// # Example
450
    ///
451
    /// ```rust,ignore
452
    /// use crate::util::value::MultiValues;
453
    ///
454
    /// let multi = MultiValues::Int32(vec![1, 2, 3]);
455
    ///
456
    /// // Through type inference
457
    /// let nums: Vec<i32> = multi.get().unwrap();
458
    /// assert_eq!(nums, vec![1, 2, 3]);
459
    ///
460
    /// // Explicitly specify type parameter
461
    /// let nums = multi.get::<i32>().unwrap();
462
    /// assert_eq!(nums, vec![1, 2, 3]);
463
    /// ```
464
    pub fn get<T>(&self) -> ValueResult<Vec<T>>
62✔
465
    where
62✔
466
        Self: MultiValuesGetter<T>,
62✔
467
    {
468
        <Self as MultiValuesGetter<T>>::get_values(self)
62✔
469
    }
62✔
470

471
    /// Generic getter method for the first value
472
    ///
473
    /// Automatically selects the correct getter method based on the target type,
474
    /// performing strict type checking.
475
    ///
476
    /// # Type Parameters
477
    ///
478
    /// * `T` - The target element type to retrieve.
479
    ///
480
    /// # Returns
481
    ///
482
    /// If types match and a value exists, returns the first value; otherwise
483
    /// returns an error.
484
    ///
485
    /// # Example
486
    ///
487
    /// ```rust,ignore
488
    /// use crate::util::value::MultiValues;
489
    ///
490
    /// let multi = MultiValues::Int32(vec![42, 100, 200]);
491
    ///
492
    /// // Through type inference
493
    /// let first: i32 = multi.get_first().unwrap();
494
    /// assert_eq!(first, 42);
495
    ///
496
    /// // Explicitly specify type parameter
497
    /// let first = multi.get_first::<i32>().unwrap();
498
    /// assert_eq!(first, 42);
499
    ///
500
    /// // String type
501
    /// let multi = MultiValues::String(vec!["hello".to_string(), "world".to_string()]);
502
    /// let first: String = multi.get_first().unwrap();
503
    /// assert_eq!(first, "hello");
504
    /// ```
505
    pub fn get_first<T>(&self) -> ValueResult<T>
40✔
506
    where
40✔
507
        Self: MultiValuesFirstGetter<T>,
40✔
508
    {
509
        <Self as MultiValuesFirstGetter<T>>::get_first_value(self)
40✔
510
    }
40✔
511

512
    /// Generic setter method
513
    ///
514
    /// Automatically selects the optimal setter path based on the input type,
515
    /// replacing the entire list with strict type checking.
516
    ///
517
    /// Supports three input forms, all unified to this method via internal
518
    /// dispatch traits:
519
    ///
520
    /// - `Vec<T>`: Takes `set_values(Vec<T>)` path with zero additional allocation
521
    /// - `&[T]`: Takes `set_values_slice(&[T])` path
522
    /// - `T`: Takes `set_single_value(T)` path
523
    ///
524
    /// # Type Parameters
525
    ///
526
    /// * `S` - Input type, can be `Vec<T>`, `&[T]`, or a single `T`
527
    ///
528
    /// # Parameters
529
    ///
530
    /// * `values` - The value collection to set, can be `Vec<T>`, `&[T]`, or a
531
    ///   single `T`
532
    ///
533
    /// # Returns
534
    ///
535
    /// If setting succeeds, returns `Ok(())`; otherwise returns an error.
536
    ///
537
    /// # Example
538
    ///
539
    /// ```rust,ignore
540
    /// use crate::lang::DataType;
541
    /// use crate::util::value::MultiValues;
542
    ///
543
    /// // 1) Vec<T>
544
    /// let mut mv = MultiValues::Empty(DataType::Int32);
545
    /// mv.set(vec![42, 100, 200]).unwrap();
546
    /// assert_eq!(mv.get_int32s().unwrap(), &[42, 100, 200]);
547
    ///
548
    /// // 2) &[T]
549
    /// let mut mv = MultiValues::Empty(DataType::Int32);
550
    /// let slice = &[7, 8, 9][..];
551
    /// mv.set(slice).unwrap();
552
    /// assert_eq!(mv.get_int32s().unwrap(), &[7, 8, 9]);
553
    ///
554
    /// // 3) Single T
555
    /// let mut mv = MultiValues::Empty(DataType::Int32);
556
    /// mv.set(42).unwrap();
557
    /// assert_eq!(mv.get_int32s().unwrap(), &[42]);
558
    ///
559
    /// // String example
560
    /// let mut mv = MultiValues::Empty(DataType::String);
561
    /// mv.set(vec!["hello".to_string(), "world".to_string()]).unwrap();
562
    /// assert_eq!(mv.get_strings().unwrap(), &["hello", "world"]);
563
    /// ```
564
    pub fn set<'a, S>(&mut self, values: S) -> ValueResult<()>
112✔
565
    where
112✔
566
        S: MultiValuesSetArg<'a>,
112✔
567
        Self: MultiValuesSetter<S::Item>
112✔
568
            + MultiValuesSetterSlice<S::Item>
112✔
569
            + MultiValuesSingleSetter<S::Item>,
112✔
570
    {
571
        values.apply(self)
112✔
572
    }
112✔
573

574
    /// Generic add method
575
    ///
576
    /// Automatically selects the optimal add path based on the input type,
577
    /// appending elements to the existing list with strict type checking.
578
    ///
579
    /// Supports three input forms:
580
    ///
581
    /// - `T`: Takes `add_value(T)` path, appending a single element
582
    /// - `Vec<T>`: Takes `add_values(Vec<T>)` path, batch append (zero additional allocation)
583
    /// - `&[T]`: Takes `add_values_slice(&[T])` path, batch append (using slice)
584
    ///
585
    /// # Type Parameters
586
    ///
587
    /// * `S` - Input type, can be a single `T`, `Vec<T>`, or `&[T]`
588
    ///
589
    /// # Example
590
    ///
591
    /// ```rust,ignore
592
    /// use crate::lang::DataType;
593
    /// use crate::util::value::MultiValues;
594
    ///
595
    /// // 1) Single T
596
    /// let mut mv = MultiValues::Int32(vec![42]);
597
    /// mv.add(100).unwrap();
598
    /// assert_eq!(mv.get_int32s().unwrap(), &[42, 100]);
599
    ///
600
    /// // 2) Vec<T>
601
    /// mv.add(vec![200, 300]).unwrap();
602
    /// assert_eq!(mv.get_int32s().unwrap(), &[42, 100, 200, 300]);
603
    ///
604
    /// // 3) &[T]
605
    /// let slice = &[400, 500][..];
606
    /// mv.add(slice).unwrap();
607
    /// assert_eq!(mv.get_int32s().unwrap(), &[42, 100, 200, 300, 400, 500]);
608
    /// ```
609
    pub fn add<'a, S>(&mut self, values: S) -> ValueResult<()>
114✔
610
    where
114✔
611
        S: MultiValuesAddArg<'a>,
114✔
612
        Self: MultiValuesAdder<S::Item> + MultiValuesMultiAdder<S::Item>,
114✔
613
    {
614
        values.apply_add(self)
114✔
615
    }
114✔
616

617
    /// Get the data type of the values
618
    ///
619
    /// # Returns
620
    ///
621
    /// Returns the data type corresponding to these multiple values
622
    ///
623
    /// # Example
624
    ///
625
    /// ```rust,ignore
626
    /// use crate::util::value::{MultiValues, DataType};
627
    ///
628
    /// let values = MultiValues::Int32(vec![1, 2, 3]);
629
    /// assert_eq!(values.data_type(), DataType::Int32);
630
    /// ```
631
    pub fn data_type(&self) -> DataType {
834✔
632
        match self {
834✔
633
            MultiValues::Empty(dt) => *dt,
84✔
634
            MultiValues::Bool(_) => DataType::Bool,
20✔
635
            MultiValues::Char(_) => DataType::Char,
12✔
636
            MultiValues::Int8(_) => DataType::Int8,
18✔
637
            MultiValues::Int16(_) => DataType::Int16,
18✔
638
            MultiValues::Int32(_) => DataType::Int32,
346✔
639
            MultiValues::Int64(_) => DataType::Int64,
24✔
640
            MultiValues::Int128(_) => DataType::Int128,
18✔
641
            MultiValues::UInt8(_) => DataType::UInt8,
20✔
642
            MultiValues::UInt16(_) => DataType::UInt16,
18✔
643
            MultiValues::UInt32(_) => DataType::UInt32,
18✔
644
            MultiValues::UInt64(_) => DataType::UInt64,
18✔
645
            MultiValues::UInt128(_) => DataType::UInt128,
18✔
646
            MultiValues::Float32(_) => DataType::Float32,
20✔
647
            MultiValues::Float64(_) => DataType::Float64,
18✔
648
            MultiValues::String(_) => DataType::String,
34✔
649
            MultiValues::Date(_) => DataType::Date,
10✔
650
            MultiValues::Time(_) => DataType::Time,
10✔
651
            MultiValues::DateTime(_) => DataType::DateTime,
10✔
652
            MultiValues::Instant(_) => DataType::Instant,
10✔
653
            MultiValues::BigInteger(_) => DataType::BigInteger,
14✔
654
            MultiValues::BigDecimal(_) => DataType::BigDecimal,
14✔
655
            MultiValues::IntSize(_) => DataType::IntSize,
26✔
656
            MultiValues::UIntSize(_) => DataType::UIntSize,
4✔
657
            MultiValues::Duration(_) => DataType::Duration,
10✔
658
            MultiValues::Url(_) => DataType::Url,
6✔
659
            MultiValues::StringMap(_) => DataType::StringMap,
6✔
660
            MultiValues::Json(_) => DataType::Json,
10✔
661
        }
662
    }
834✔
663

664
    /// Get the number of values
665
    ///
666
    /// # Returns
667
    ///
668
    /// Returns the number of values contained in these multiple values
669
    ///
670
    /// # Example
671
    ///
672
    /// ```rust,ignore
673
    /// use crate::util::value::MultiValues;
674
    ///
675
    /// let values = MultiValues::Int32(vec![1, 2, 3]);
676
    /// assert_eq!(values.count(), 3);
677
    ///
678
    /// let empty = MultiValues::Empty(DataType::String);
679
    /// assert_eq!(empty.count(), 0);
680
    /// ```
681
    pub fn count(&self) -> usize {
696✔
682
        match self {
696✔
683
            MultiValues::Empty(_) => 0,
26✔
684
            MultiValues::Bool(v) => v.len(),
36✔
685
            MultiValues::Char(v) => v.len(),
22✔
686
            MultiValues::Int8(v) => v.len(),
32✔
687
            MultiValues::Int16(v) => v.len(),
32✔
688
            MultiValues::Int32(v) => v.len(),
66✔
689
            MultiValues::Int64(v) => v.len(),
32✔
690
            MultiValues::Int128(v) => v.len(),
32✔
691
            MultiValues::UInt8(v) => v.len(),
34✔
692
            MultiValues::UInt16(v) => v.len(),
32✔
693
            MultiValues::UInt32(v) => v.len(),
32✔
694
            MultiValues::UInt64(v) => v.len(),
34✔
695
            MultiValues::UInt128(v) => v.len(),
32✔
696
            MultiValues::Float32(v) => v.len(),
32✔
697
            MultiValues::Float64(v) => v.len(),
34✔
698
            MultiValues::String(v) => v.len(),
56✔
699
            MultiValues::Date(v) => v.len(),
8✔
700
            MultiValues::Time(v) => v.len(),
8✔
701
            MultiValues::DateTime(v) => v.len(),
8✔
702
            MultiValues::Instant(v) => v.len(),
8✔
703
            MultiValues::BigInteger(v) => v.len(),
24✔
704
            MultiValues::BigDecimal(v) => v.len(),
24✔
705
            MultiValues::IntSize(v) => v.len(),
12✔
706
            MultiValues::UIntSize(v) => v.len(),
6✔
707
            MultiValues::Duration(v) => v.len(),
10✔
708
            MultiValues::Url(v) => v.len(),
8✔
709
            MultiValues::StringMap(v) => v.len(),
8✔
710
            MultiValues::Json(v) => v.len(),
8✔
711
        }
712
    }
696✔
713

714
    /// Check if empty
715
    ///
716
    /// # Returns
717
    ///
718
    /// Returns `true` if these multiple values do not contain any values
719
    ///
720
    /// # Example
721
    ///
722
    /// ```rust,ignore
723
    /// use crate::util::value::{MultiValues, DataType};
724
    ///
725
    /// let values = MultiValues::Int32(vec![]);
726
    /// assert!(values.is_empty());
727
    ///
728
    /// let empty = MultiValues::Empty(DataType::String);
729
    /// assert!(empty.is_empty());
730
    /// ```
731
    pub fn is_empty(&self) -> bool {
70✔
732
        self.count() == 0
70✔
733
    }
70✔
734

735
    /// Clear all values while preserving the type
736
    ///
737
    /// # Example
738
    ///
739
    /// ```rust,ignore
740
    /// use crate::util::value::{MultiValues, DataType};
741
    ///
742
    /// let mut values = MultiValues::Int32(vec![1, 2, 3]);
743
    /// values.clear();
744
    /// assert!(values.is_empty());
745
    /// assert_eq!(values.data_type(), DataType::Int32);
746
    /// ```
747
    pub fn clear(&mut self) {
50✔
748
        match self {
50✔
749
            MultiValues::Empty(_) => {}
2✔
750
            MultiValues::Bool(v) => v.clear(),
2✔
751
            MultiValues::Char(v) => v.clear(),
2✔
752
            MultiValues::Int8(v) => v.clear(),
2✔
753
            MultiValues::Int16(v) => v.clear(),
2✔
754
            MultiValues::Int32(v) => v.clear(),
6✔
755
            MultiValues::Int64(v) => v.clear(),
2✔
756
            MultiValues::Int128(v) => v.clear(),
2✔
757
            MultiValues::UInt8(v) => v.clear(),
2✔
758
            MultiValues::UInt16(v) => v.clear(),
2✔
759
            MultiValues::UInt32(v) => v.clear(),
2✔
760
            MultiValues::UInt64(v) => v.clear(),
2✔
761
            MultiValues::UInt128(v) => v.clear(),
2✔
762
            MultiValues::Float32(v) => v.clear(),
2✔
763
            MultiValues::Float64(v) => v.clear(),
2✔
764
            MultiValues::String(v) => v.clear(),
2✔
765
            MultiValues::Date(v) => v.clear(),
2✔
766
            MultiValues::Time(v) => v.clear(),
2✔
767
            MultiValues::DateTime(v) => v.clear(),
2✔
768
            MultiValues::Instant(v) => v.clear(),
2✔
769
            MultiValues::BigInteger(v) => v.clear(),
2✔
770
            MultiValues::BigDecimal(v) => v.clear(),
2✔
771
            MultiValues::IntSize(v) => v.clear(),
2✔
772
            MultiValues::UIntSize(v) => v.clear(),
×
773
            MultiValues::Duration(v) => v.clear(),
×
774
            MultiValues::Url(v) => v.clear(),
×
775
            MultiValues::StringMap(v) => v.clear(),
×
776
            MultiValues::Json(v) => v.clear(),
×
777
        }
778
    }
50✔
779

780
    /// Set the data type
781
    ///
782
    /// If the new type differs from the current type, clears all values and
783
    /// sets the new type.
784
    ///
785
    /// # Parameters
786
    ///
787
    /// * `data_type` - The data type to set
788
    ///
789
    /// # Example
790
    ///
791
    /// ```rust,ignore
792
    /// use crate::util::value::{MultiValues, DataType};
793
    ///
794
    /// let mut values = MultiValues::Int32(vec![1, 2, 3]);
795
    /// values.set_type(DataType::String);
796
    /// assert!(values.is_empty());
797
    /// assert_eq!(values.data_type(), DataType::String);
798
    /// ```
799
    pub fn set_type(&mut self, data_type: DataType) {
6✔
800
        if self.data_type() != data_type {
6✔
801
            *self = MultiValues::Empty(data_type);
4✔
802
        }
4✔
803
    }
6✔
804

805
    // ========================================================================
806
    // Get first value (as single value access)
807
    // ========================================================================
808

809
    impl_get_first_value! {
810
        /// Get the first boolean value.
811
        ///
812
        /// # Returns
813
        ///
814
        /// If types match and a value exists, returns the first boolean value;
815
        /// otherwise returns an error.
816
        ///
817
        /// # Example
818
        ///
819
        /// ```rust,ignore
820
        /// use crate::util::value::MultiValues;
821
        ///
822
        /// let values = MultiValues::Bool(vec![true, false]);
823
        /// assert_eq!(values.get_first_bool().unwrap(), true);
824
        /// ```
825
        copy: get_first_bool, Bool, bool, DataType::Bool
826
    }
827

828
    impl_get_first_value! {
829
        /// Get the first character value
830
        ///
831
        /// # Returns
832
        ///
833
        /// If types match and a value exists, returns the first character value;
834
        /// otherwise returns an error.
835
        copy: get_first_char, Char, char, DataType::Char
836
    }
837

838
    impl_get_first_value! {
839
        /// Get the first int8 value
840
        ///
841
        /// # Returns
842
        ///
843
        /// If types match and a value exists, returns the first int8 value;
844
        /// otherwise returns an error
845
        copy: get_first_int8, Int8, i8, DataType::Int8
846
    }
847

848
    impl_get_first_value! {
849
        /// Get the first int16 value
850
        ///
851
        /// # Returns
852
        ///
853
        /// If types match and a value exists, returns the first int16 value;
854
        /// otherwise returns an error
855
        copy: get_first_int16, Int16, i16, DataType::Int16
856
    }
857

858
    impl_get_first_value! {
859
        /// Get the first int32 value
860
        ///
861
        /// # Returns
862
        ///
863
        /// If types match and a value exists, returns the first int32 value;
864
        /// otherwise returns an error
865
        copy: get_first_int32, Int32, i32, DataType::Int32
866
    }
867

868
    impl_get_first_value! {
869
        /// Get the first int64 value
870
        ///
871
        /// # Returns
872
        ///
873
        /// If types match and a value exists, returns the first int64 value;
874
        /// otherwise returns an error
875
        copy: get_first_int64, Int64, i64, DataType::Int64
876
    }
877

878
    impl_get_first_value! {
879
        /// Get the first int128 value
880
        ///
881
        /// # Returns
882
        ///
883
        /// If types match and a value exists, returns the first int128 value;
884
        /// otherwise returns an error
885
        copy: get_first_int128, Int128, i128, DataType::Int128
886
    }
887

888
    impl_get_first_value! {
889
        /// Get the first uint8 value
890
        ///
891
        /// # Returns
892
        ///
893
        /// If types match and a value exists, returns the first uint8 value;
894
        /// otherwise returns an error
895
        copy: get_first_uint8, UInt8, u8, DataType::UInt8
896
    }
897

898
    impl_get_first_value! {
899
        /// Get the first uint16 value
900
        ///
901
        /// # Returns
902
        ///
903
        /// If types match and a value exists, returns the first uint16 value;
904
        /// otherwise returns an error
905
        copy: get_first_uint16, UInt16, u16, DataType::UInt16
906
    }
907

908
    impl_get_first_value! {
909
        /// Get the first uint32 value
910
        ///
911
        /// # Returns
912
        ///
913
        /// If types match and a value exists, returns the first uint32 value;
914
        /// otherwise returns an error
915
        copy: get_first_uint32, UInt32, u32, DataType::UInt32
916
    }
917

918
    impl_get_first_value! {
919
        /// Get the first uint64 value
920
        ///
921
        /// # Returns
922
        ///
923
        /// If types match and a value exists, returns the first uint64 value;
924
        /// otherwise returns an error
925
        copy: get_first_uint64, UInt64, u64, DataType::UInt64
926
    }
927

928
    impl_get_first_value! {
929
        /// Get the first uint128 value
930
        ///
931
        /// # Returns
932
        ///
933
        /// If types match and a value exists, returns the first uint128 value;
934
        /// otherwise returns an error
935
        copy: get_first_uint128, UInt128, u128, DataType::UInt128
936
    }
937

938
    impl_get_first_value! {
939
        /// Get the first float32 value
940
        ///
941
        /// # Returns
942
        ///
943
        /// If types match and a value exists, returns the first float32 value;
944
        /// otherwise returns an error
945
        copy: get_first_float32, Float32, f32, DataType::Float32
946
    }
947

948
    impl_get_first_value! {
949
        /// Get the first float64 value
950
        ///
951
        /// # Returns
952
        ///
953
        /// If types match and a value exists, returns the first float64 value;
954
        /// otherwise returns an error
955
        copy: get_first_float64, Float64, f64, DataType::Float64
956
    }
957

958
    impl_get_first_value! {
959
        /// Get the first string reference
960
        ///
961
        /// # Returns
962
        ///
963
        /// If types match and a value exists, returns a reference to the first
964
        /// string; otherwise returns an error
965
        ref: get_first_string, String, &str, DataType::String, |s: &String| s.as_str()
8✔
966
    }
967

968
    impl_get_first_value! {
969
        /// Get the first date value
970
        ///
971
        /// # Returns
972
        ///
973
        /// If types match and a value exists, returns the first date value;
974
        /// otherwise returns an error
975
        copy: get_first_date, Date, NaiveDate, DataType::Date
976
    }
977

978
    impl_get_first_value! {
979
        /// Get the first time value
980
        ///
981
        /// # Returns
982
        ///
983
        /// If types match and a value exists, returns the first time value;
984
        /// otherwise returns an error
985
        copy: get_first_time, Time, NaiveTime, DataType::Time
986
    }
987

988
    impl_get_first_value! {
989
        /// Get the first datetime value
990
        ///
991
        /// # Returns
992
        ///
993
        /// If types match and a value exists, returns the first datetime value;
994
        /// otherwise returns an error
995
        copy: get_first_datetime, DateTime, NaiveDateTime, DataType::DateTime
996
    }
997

998
    impl_get_first_value! {
999
        /// Get the first UTC instant value
1000
        ///
1001
        /// # Returns
1002
        ///
1003
        /// If types match and a value exists, returns the first UTC instant
1004
        /// value; otherwise returns an error
1005
        copy: get_first_instant, Instant, DateTime<Utc>, DataType::Instant
1006
    }
1007

1008
    impl_get_first_value! {
1009
        /// Get the first big integer value
1010
        ///
1011
        /// # Returns
1012
        ///
1013
        /// If types match and a value exists, returns the first big integer
1014
        /// value; otherwise returns an error
1015
        ref: get_first_biginteger, BigInteger, BigInt, DataType::BigInteger, |v: &BigInt| v.clone()
12✔
1016
    }
1017

1018
    impl_get_first_value! {
1019
        /// Get the first big decimal value
1020
        ///
1021
        /// # Returns
1022
        ///
1023
        /// If types match and a value exists, returns the first big decimal
1024
        /// value; otherwise returns an error
1025
        ref: get_first_bigdecimal, BigDecimal, BigDecimal, DataType::BigDecimal, |v: &BigDecimal| v.clone()
12✔
1026
    }
1027

1028
    impl_get_first_value! {
1029
        /// Get the first isize value
1030
        copy: get_first_intsize, IntSize, isize, DataType::IntSize
1031
    }
1032

1033
    impl_get_first_value! {
1034
        /// Get the first usize value
1035
        copy: get_first_uintsize, UIntSize, usize, DataType::UIntSize
1036
    }
1037

1038
    impl_get_first_value! {
1039
        /// Get the first Duration value
1040
        copy: get_first_duration, Duration, Duration, DataType::Duration
1041
    }
1042

1043
    impl_get_first_value! {
1044
        /// Get the first Url value
1045
        ref: get_first_url, Url, Url, DataType::Url, |v: &Url| v.clone()
6✔
1046
    }
1047

1048
    impl_get_first_value! {
1049
        /// Get the first StringMap value
1050
        ref: get_first_string_map, StringMap, HashMap<String, String>, DataType::StringMap, |v: &HashMap<String, String>| v.clone()
6✔
1051
    }
1052

1053
    impl_get_first_value! {
1054
        /// Get the first Json value
1055
        ref: get_first_json, Json, serde_json::Value, DataType::Json, |v: &serde_json::Value| v.clone()
4✔
1056
    }
1057

1058
    // ========================================================================
1059
    // Get all values (type checking)
1060
    // ========================================================================
1061

1062
    impl_get_multi_values! {
1063
        /// Get reference to all boolean values
1064
        ///
1065
        /// # Returns
1066
        ///
1067
        /// If types match, returns a reference to the boolean value array;
1068
        /// otherwise returns an error
1069
        ///
1070
        /// # Example
1071
        ///
1072
        /// ```rust,ignore
1073
        /// use crate::util::value::MultiValues;
1074
        ///
1075
        /// let values = MultiValues::Bool(vec![true, false, true]);
1076
        /// assert_eq!(values.get_bools().unwrap(), &[true, false, true]);
1077
        /// ```
1078
        slice: get_bools, Bool, bool, DataType::Bool
1079
    }
1080

1081
    impl_get_multi_values! {
1082
        /// Get reference to all character values
1083
        ///
1084
        /// # Returns
1085
        ///
1086
        /// If types match, returns a reference to the character value array;
1087
        /// otherwise returns an error
1088
        slice: get_chars, Char, char, DataType::Char
1089
    }
1090

1091
    impl_get_multi_values! {
1092
        /// Get reference to all int8 values
1093
        ///
1094
        /// # Returns
1095
        ///
1096
        /// If types match, returns a reference to the int8 value array;
1097
        /// otherwise returns an error
1098
        slice: get_int8s, Int8, i8, DataType::Int8
1099
    }
1100

1101
    impl_get_multi_values! {
1102
        /// Get reference to all int16 values
1103
        ///
1104
        /// # Returns
1105
        ///
1106
        /// If types match, returns a reference to the int16 value array;
1107
        /// otherwise returns an error
1108
        slice: get_int16s, Int16, i16, DataType::Int16
1109
    }
1110

1111
    impl_get_multi_values! {
1112
        /// Get reference to all int32 values
1113
        ///
1114
        /// # Returns
1115
        ///
1116
        /// If types match, returns a reference to the int32 value array;
1117
        /// otherwise returns an error
1118
        slice: get_int32s, Int32, i32, DataType::Int32
1119
    }
1120

1121
    impl_get_multi_values! {
1122
        /// Get reference to all int64 values
1123
        ///
1124
        /// # Returns
1125
        ///
1126
        /// If types match, returns a reference to the int64 value array;
1127
        /// otherwise returns an error
1128
        slice: get_int64s, Int64, i64, DataType::Int64
1129
    }
1130

1131
    impl_get_multi_values! {
1132
        /// Get reference to all int128 values
1133
        ///
1134
        /// # Returns
1135
        ///
1136
        /// If types match, returns a reference to the int128 value array;
1137
        /// otherwise returns an error
1138
        slice: get_int128s, Int128, i128, DataType::Int128
1139
    }
1140

1141
    impl_get_multi_values! {
1142
        /// Get reference to all uint8 values
1143
        ///
1144
        /// # Returns
1145
        ///
1146
        /// If types match, returns a reference to the uint8 value array;
1147
        /// otherwise returns an error
1148
        slice: get_uint8s, UInt8, u8, DataType::UInt8
1149
    }
1150

1151
    impl_get_multi_values! {
1152
        /// Get reference to all uint16 values
1153
        ///
1154
        /// # Returns
1155
        ///
1156
        /// If types match, returns a reference to the uint16 value array;
1157
        /// otherwise returns an error
1158
        slice: get_uint16s, UInt16, u16, DataType::UInt16
1159
    }
1160

1161
    impl_get_multi_values! {
1162
        /// Get reference to all uint32 values
1163
        ///
1164
        /// # Returns
1165
        ///
1166
        /// If types match, returns a reference to the uint32 value array;
1167
        /// otherwise returns an error
1168
        slice: get_uint32s, UInt32, u32, DataType::UInt32
1169
    }
1170

1171
    impl_get_multi_values! {
1172
        /// Get reference to all uint64 values
1173
        ///
1174
        /// # Returns
1175
        ///
1176
        /// If types match, returns a reference to the uint64 value array;
1177
        /// otherwise returns an error
1178
        slice: get_uint64s, UInt64, u64, DataType::UInt64
1179
    }
1180

1181
    impl_get_multi_values! {
1182
        /// Get reference to all uint128 values
1183
        ///
1184
        /// # Returns
1185
        ///
1186
        /// If types match, returns a reference to the uint128 value array;
1187
        /// otherwise returns an error
1188
        slice: get_uint128s, UInt128, u128, DataType::UInt128
1189
    }
1190

1191
    impl_get_multi_values! {
1192
        /// Get reference to all float32 values
1193
        ///
1194
        /// # Returns
1195
        ///
1196
        /// If types match, returns a reference to the float32 value array;
1197
        /// otherwise returns an error
1198
        slice: get_float32s, Float32, f32, DataType::Float32
1199
    }
1200

1201
    impl_get_multi_values! {
1202
        /// Get reference to all float64 values
1203
        ///
1204
        /// # Returns
1205
        ///
1206
        /// If types match, returns a reference to the float64 value array;
1207
        /// otherwise returns an error
1208
        slice: get_float64s, Float64, f64, DataType::Float64
1209
    }
1210

1211
    impl_get_multi_values! {
1212
        /// Get reference to all strings
1213
        ///
1214
        /// # Returns
1215
        ///
1216
        /// If types match, returns a reference to the string array; otherwise
1217
        /// returns an error
1218
        vec: get_strings, String, String, DataType::String
1219
    }
1220

1221
    impl_get_multi_values! {
1222
        /// Get reference to all date values
1223
        ///
1224
        /// # Returns
1225
        ///
1226
        /// If types match, returns a reference to the date value array;
1227
        /// otherwise returns an error
1228
        slice: get_dates, Date, NaiveDate, DataType::Date
1229
    }
1230

1231
    impl_get_multi_values! {
1232
        /// Get reference to all time values
1233
        ///
1234
        /// # Returns
1235
        ///
1236
        /// If types match, returns a reference to the time value array;
1237
        /// otherwise returns an error
1238
        slice: get_times, Time, NaiveTime, DataType::Time
1239
    }
1240

1241
    impl_get_multi_values! {
1242
        /// Get reference to all datetime values
1243
        ///
1244
        /// # Returns
1245
        ///
1246
        /// If types match, returns a reference to the datetime value array;
1247
        /// otherwise returns an error
1248
        slice: get_datetimes, DateTime, NaiveDateTime, DataType::DateTime
1249
    }
1250

1251
    impl_get_multi_values! {
1252
        /// Get reference to all UTC instant values
1253
        ///
1254
        /// # Returns
1255
        ///
1256
        /// If types match, returns a reference to the UTC instant value array;
1257
        /// otherwise returns an error
1258
        slice: get_instants, Instant, DateTime<Utc>, DataType::Instant
1259
    }
1260

1261
    impl_get_multi_values! {
1262
        /// Get reference to all big integers
1263
        ///
1264
        /// # Returns
1265
        ///
1266
        /// If types match, returns a reference to the big integer array;
1267
        /// otherwise returns an error
1268
        vec: get_bigintegers, BigInteger, BigInt, DataType::BigInteger
1269
    }
1270

1271
    impl_get_multi_values! {
1272
        /// Get reference to all big decimals
1273
        ///
1274
        /// # Returns
1275
        ///
1276
        /// If types match, returns a reference to the big decimal array;
1277
        /// otherwise returns an error
1278
        vec: get_bigdecimals, BigDecimal, BigDecimal, DataType::BigDecimal
1279
    }
1280

1281
    impl_get_multi_values! {
1282
        /// Get reference to all isize values
1283
        slice: get_intsizes, IntSize, isize, DataType::IntSize
1284
    }
1285

1286
    impl_get_multi_values! {
1287
        /// Get reference to all usize values
1288
        slice: get_uintsizes, UIntSize, usize, DataType::UIntSize
1289
    }
1290

1291
    impl_get_multi_values! {
1292
        /// Get reference to all Duration values
1293
        slice: get_durations, Duration, Duration, DataType::Duration
1294
    }
1295

1296
    impl_get_multi_values! {
1297
        /// Get reference to all Url values
1298
        vec: get_urls, Url, Url, DataType::Url
1299
    }
1300

1301
    impl_get_multi_values! {
1302
        /// Get reference to all StringMap values
1303
        vec: get_string_maps, StringMap, HashMap<String, String>, DataType::StringMap
1304
    }
1305

1306
    impl_get_multi_values! {
1307
        /// Get reference to all Json values
1308
        vec: get_jsons, Json, serde_json::Value, DataType::Json
1309
    }
1310

1311
    // ========================================================================
1312
    // Set value operations
1313
    // ========================================================================
1314

1315
    impl_set_multi_values! {
1316
        /// Set all boolean values
1317
        ///
1318
        /// # Parameters
1319
        ///
1320
        /// * `values` - The list of boolean values to set
1321
        ///
1322
        /// # Returns
1323
        ///
1324
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1325
        ///
1326
        /// # Example
1327
        ///
1328
        /// ```rust,ignore
1329
        /// use crate::util::value::MultiValues;
1330
        ///
1331
        /// let mut values = MultiValues::Empty(DataType::Bool);
1332
        /// values.set_bools(vec![true, false, true]).unwrap();
1333
        /// assert_eq!(values.get_bools().unwrap(), &[true, false, true]);
1334
        /// ```
1335
        set_bools, Bool, bool, DataType::Bool
1336
    }
1337

1338
    impl_set_multi_values! {
1339
        /// Set all character values
1340
        ///
1341
        /// # Parameters
1342
        ///
1343
        /// * `values` - The list of character values to set
1344
        ///
1345
        /// # Returns
1346
        ///
1347
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1348
        set_chars, Char, char, DataType::Char
1349
    }
1350

1351
    impl_set_multi_values! {
1352
        /// Set all int8 values
1353
        ///
1354
        /// # Parameters
1355
        ///
1356
        /// * `values` - The list of int8 values to set
1357
        ///
1358
        /// # Returns
1359
        ///
1360
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1361
        set_int8s, Int8, i8, DataType::Int8
1362
    }
1363

1364
    impl_set_multi_values! {
1365
        /// Set all int16 values
1366
        ///
1367
        /// # Parameters
1368
        ///
1369
        /// * `values` - The list of int16 values to set
1370
        ///
1371
        /// # Returns
1372
        ///
1373
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1374
        set_int16s, Int16, i16, DataType::Int16
1375
    }
1376

1377
    impl_set_multi_values! {
1378
        /// Set all int32 values
1379
        ///
1380
        /// # Parameters
1381
        ///
1382
        /// * `values` - The list of int32 values to set
1383
        ///
1384
        /// # Returns
1385
        ///
1386
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1387
        set_int32s, Int32, i32, DataType::Int32
1388
    }
1389

1390
    impl_set_multi_values! {
1391
        /// Set all int64 values
1392
        ///
1393
        /// # Parameters
1394
        ///
1395
        /// * `values` - The list of int64 values to set
1396
        ///
1397
        /// # Returns
1398
        ///
1399
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1400
        set_int64s, Int64, i64, DataType::Int64
1401
    }
1402

1403
    impl_set_multi_values! {
1404
        /// Set all int128 values
1405
        ///
1406
        /// # Parameters
1407
        ///
1408
        /// * `values` - The list of int128 values to set
1409
        ///
1410
        /// # Returns
1411
        ///
1412
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1413
        set_int128s, Int128, i128, DataType::Int128
1414
    }
1415

1416
    impl_set_multi_values! {
1417
        /// Set all uint8 values
1418
        ///
1419
        /// # Parameters
1420
        ///
1421
        /// * `values` - The list of uint8 values to set
1422
        ///
1423
        /// # Returns
1424
        ///
1425
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1426
        set_uint8s, UInt8, u8, DataType::UInt8
1427
    }
1428

1429
    impl_set_multi_values! {
1430
        /// Set all uint16 values
1431
        ///
1432
        /// # Parameters
1433
        ///
1434
        /// * `values` - The list of uint16 values to set
1435
        ///
1436
        /// # Returns
1437
        ///
1438
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1439
        set_uint16s, UInt16, u16, DataType::UInt16
1440
    }
1441

1442
    impl_set_multi_values! {
1443
        /// Set all uint32 values
1444
        ///
1445
        /// # Parameters
1446
        ///
1447
        /// * `values` - The list of uint32 values to set
1448
        ///
1449
        /// # Returns
1450
        ///
1451
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1452
        set_uint32s, UInt32, u32, DataType::UInt32
1453
    }
1454

1455
    impl_set_multi_values! {
1456
        /// Set all uint64 values
1457
        ///
1458
        /// # Parameters
1459
        ///
1460
        /// * `values` - The list of uint64 values to set
1461
        ///
1462
        /// # Returns
1463
        ///
1464
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1465
        set_uint64s, UInt64, u64, DataType::UInt64
1466
    }
1467

1468
    impl_set_multi_values! {
1469
        /// Set all uint128 values
1470
        ///
1471
        /// # Parameters
1472
        ///
1473
        /// * `values` - The list of uint128 values to set
1474
        ///
1475
        /// # Returns
1476
        ///
1477
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1478
        set_uint128s, UInt128, u128, DataType::UInt128
1479
    }
1480

1481
    impl_set_multi_values! {
1482
        /// Set all float32 values
1483
        ///
1484
        /// # Parameters
1485
        ///
1486
        /// * `values` - The list of float32 values to set
1487
        ///
1488
        /// # Returns
1489
        ///
1490
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1491
        set_float32s, Float32, f32, DataType::Float32
1492
    }
1493

1494
    impl_set_multi_values! {
1495
        /// Set all float64 values
1496
        ///
1497
        /// # Parameters
1498
        ///
1499
        /// * `values` - The list of float64 values to set
1500
        ///
1501
        /// # Returns
1502
        ///
1503
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1504
        set_float64s, Float64, f64, DataType::Float64
1505
    }
1506

1507
    impl_set_multi_values! {
1508
        /// Set all string values
1509
        ///
1510
        /// # Parameters
1511
        ///
1512
        /// * `values` - The list of string values to set
1513
        ///
1514
        /// # Returns
1515
        ///
1516
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1517
        ///
1518
        /// # Example
1519
        ///
1520
        /// ```rust,ignore
1521
        /// use crate::util::value::MultiValues;
1522
        ///
1523
        /// let mut values = MultiValues::Empty(DataType::String);
1524
        /// values.set_strings(vec!["hello".to_string(), "world".to_string()]).unwrap();
1525
        /// assert_eq!(values.get_strings().unwrap(), &["hello", "world"]);
1526
        /// ```
1527
        set_strings, String, String, DataType::String
1528
    }
1529

1530
    impl_set_multi_values! {
1531
        /// Set all date values
1532
        ///
1533
        /// # Parameters
1534
        ///
1535
        /// * `values` - The list of date values to set
1536
        ///
1537
        /// # Returns
1538
        ///
1539
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1540
        set_dates, Date, NaiveDate, DataType::Date
1541
    }
1542

1543
    impl_set_multi_values! {
1544
        /// Set all time values
1545
        ///
1546
        /// # Parameters
1547
        ///
1548
        /// * `values` - The list of time values to set
1549
        ///
1550
        /// # Returns
1551
        ///
1552
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1553
        set_times, Time, NaiveTime, DataType::Time
1554
    }
1555

1556
    impl_set_multi_values! {
1557
        /// Set all datetime values
1558
        ///
1559
        /// # Parameters
1560
        ///
1561
        /// * `values` - The list of datetime values to set
1562
        ///
1563
        /// # Returns
1564
        ///
1565
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1566
        set_datetimes, DateTime, NaiveDateTime, DataType::DateTime
1567
    }
1568

1569
    impl_set_multi_values! {
1570
        /// Set all UTC instant values
1571
        ///
1572
        /// # Parameters
1573
        ///
1574
        /// * `values` - The list of UTC instant values to set
1575
        ///
1576
        /// # Returns
1577
        ///
1578
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1579
        set_instants, Instant, DateTime<Utc>, DataType::Instant
1580
    }
1581

1582
    impl_set_multi_values! {
1583
        /// Set all big integer values
1584
        ///
1585
        /// # Parameters
1586
        ///
1587
        /// * `values` - The list of big integer values to set
1588
        ///
1589
        /// # Returns
1590
        ///
1591
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1592
        set_bigintegers, BigInteger, BigInt, DataType::BigInteger
1593
    }
1594

1595
    impl_set_multi_values! {
1596
        /// Set all big decimal values
1597
        ///
1598
        /// # Parameters
1599
        ///
1600
        /// * `values` - The list of big decimal values to set
1601
        ///
1602
        /// # Returns
1603
        ///
1604
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1605
        set_bigdecimals, BigDecimal, BigDecimal, DataType::BigDecimal
1606
    }
1607

1608
    impl_set_multi_values! {
1609
        /// Set all isize values
1610
        set_intsizes, IntSize, isize, DataType::IntSize
1611
    }
1612

1613
    impl_set_multi_values! {
1614
        /// Set all usize values
1615
        set_uintsizes, UIntSize, usize, DataType::UIntSize
1616
    }
1617

1618
    impl_set_multi_values! {
1619
        /// Set all Duration values
1620
        set_durations, Duration, Duration, DataType::Duration
1621
    }
1622

1623
    impl_set_multi_values! {
1624
        /// Set all Url values
1625
        set_urls, Url, Url, DataType::Url
1626
    }
1627

1628
    impl_set_multi_values! {
1629
        /// Set all StringMap values
1630
        set_string_maps, StringMap, HashMap<String, String>, DataType::StringMap
1631
    }
1632

1633
    impl_set_multi_values! {
1634
        /// Set all Json values
1635
        set_jsons, Json, serde_json::Value, DataType::Json
1636
    }
1637

1638
    // ========================================================================
1639
    // Set all values via slice operations
1640
    // ========================================================================
1641

1642
    impl_set_multi_values_slice! {
1643
        /// Set all boolean values via slice
1644
        ///
1645
        /// # Parameters
1646
        ///
1647
        /// * `values` - The boolean value slice to set
1648
        ///
1649
        /// # Returns
1650
        ///
1651
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1652
        set_bools_slice, Bool, bool, DataType::Bool
1653
    }
1654

1655
    impl_set_multi_values_slice! {
1656
        /// Set all character values via slice
1657
        ///
1658
        /// # Parameters
1659
        ///
1660
        /// * `values` - The character value slice to set
1661
        ///
1662
        /// # Returns
1663
        ///
1664
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1665
        set_chars_slice, Char, char, DataType::Char
1666
    }
1667

1668
    impl_set_multi_values_slice! {
1669
        /// Set all int8 values via slice
1670
        ///
1671
        /// # Parameters
1672
        ///
1673
        /// * `values` - The int8 value slice to set
1674
        ///
1675
        /// # Returns
1676
        ///
1677
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1678
        set_int8s_slice, Int8, i8, DataType::Int8
1679
    }
1680

1681
    impl_set_multi_values_slice! {
1682
        /// Set all int16 values via slice
1683
        ///
1684
        /// # Parameters
1685
        ///
1686
        /// * `values` - The int16 value slice to set
1687
        ///
1688
        /// # Returns
1689
        ///
1690
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1691
        set_int16s_slice, Int16, i16, DataType::Int16
1692
    }
1693

1694
    impl_set_multi_values_slice! {
1695
        /// Set all int32 values via slice
1696
        ///
1697
        /// # Parameters
1698
        ///
1699
        /// * `values` - The int32 value slice to set
1700
        ///
1701
        /// # Returns
1702
        ///
1703
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1704
        set_int32s_slice, Int32, i32, DataType::Int32
1705
    }
1706

1707
    impl_set_multi_values_slice! {
1708
        /// Set all int64 values via slice
1709
        ///
1710
        /// # Parameters
1711
        ///
1712
        /// * `values` - The int64 value slice to set
1713
        ///
1714
        /// # Returns
1715
        ///
1716
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1717
        set_int64s_slice, Int64, i64, DataType::Int64
1718
    }
1719

1720
    impl_set_multi_values_slice! {
1721
        /// Set all int128 values via slice
1722
        ///
1723
        /// # Parameters
1724
        ///
1725
        /// * `values` - The int128 value slice to set
1726
        ///
1727
        /// # Returns
1728
        ///
1729
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1730
        set_int128s_slice, Int128, i128, DataType::Int128
1731
    }
1732

1733
    impl_set_multi_values_slice! {
1734
        /// Set all uint8 values via slice
1735
        ///
1736
        /// # Parameters
1737
        ///
1738
        /// * `values` - The uint8 value slice to set
1739
        ///
1740
        /// # Returns
1741
        ///
1742
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1743
        set_uint8s_slice, UInt8, u8, DataType::UInt8
1744
    }
1745

1746
    impl_set_multi_values_slice! {
1747
        /// Set all uint16 values via slice
1748
        ///
1749
        /// # Parameters
1750
        ///
1751
        /// * `values` - The uint16 value slice to set
1752
        ///
1753
        /// # Returns
1754
        ///
1755
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1756
        set_uint16s_slice, UInt16, u16, DataType::UInt16
1757
    }
1758

1759
    impl_set_multi_values_slice! {
1760
        /// Set all uint32 values via slice
1761
        ///
1762
        /// # Parameters
1763
        ///
1764
        /// * `values` - The uint32 value slice to set
1765
        ///
1766
        /// # Returns
1767
        ///
1768
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1769
        set_uint32s_slice, UInt32, u32, DataType::UInt32
1770
    }
1771

1772
    impl_set_multi_values_slice! {
1773
        /// Set all uint64 values via slice
1774
        ///
1775
        /// # Parameters
1776
        ///
1777
        /// * `values` - The uint64 value slice to set
1778
        ///
1779
        /// # Returns
1780
        ///
1781
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1782
        set_uint64s_slice, UInt64, u64, DataType::UInt64
1783
    }
1784

1785
    impl_set_multi_values_slice! {
1786
        /// Set all uint128 values via slice
1787
        ///
1788
        /// # Parameters
1789
        ///
1790
        /// * `values` - The uint128 value slice to set
1791
        ///
1792
        /// # Returns
1793
        ///
1794
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1795
        set_uint128s_slice, UInt128, u128, DataType::UInt128
1796
    }
1797

1798
    impl_set_multi_values_slice! {
1799
        /// Set all float32 values via slice
1800
        ///
1801
        /// # Parameters
1802
        ///
1803
        /// * `values` - The float32 value slice to set
1804
        ///
1805
        /// # Returns
1806
        ///
1807
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1808
        set_float32s_slice, Float32, f32, DataType::Float32
1809
    }
1810

1811
    impl_set_multi_values_slice! {
1812
        /// Set all float64 values via slice
1813
        ///
1814
        /// # Parameters
1815
        ///
1816
        /// * `values` - The float64 value slice to set
1817
        ///
1818
        /// # Returns
1819
        ///
1820
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1821
        set_float64s_slice, Float64, f64, DataType::Float64
1822
    }
1823

1824
    impl_set_multi_values_slice! {
1825
        /// Set all string values via slice
1826
        ///
1827
        /// # Parameters
1828
        ///
1829
        /// * `values` - The string value slice to set
1830
        ///
1831
        /// # Returns
1832
        ///
1833
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1834
        set_strings_slice, String, String, DataType::String
1835
    }
1836

1837
    impl_set_multi_values_slice! {
1838
        /// Set all date values via slice
1839
        ///
1840
        /// # Parameters
1841
        ///
1842
        /// * `values` - The date value slice to set
1843
        ///
1844
        /// # Returns
1845
        ///
1846
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1847
        set_dates_slice, Date, NaiveDate, DataType::Date
1848
    }
1849

1850
    impl_set_multi_values_slice! {
1851
        /// Set all time values via slice
1852
        ///
1853
        /// # Parameters
1854
        ///
1855
        /// * `values` - The time value slice to set
1856
        ///
1857
        /// # Returns
1858
        ///
1859
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1860
        set_times_slice, Time, NaiveTime, DataType::Time
1861
    }
1862

1863
    impl_set_multi_values_slice! {
1864
        /// Set all datetime values via slice
1865
        ///
1866
        /// # Parameters
1867
        ///
1868
        /// * `values` - The datetime value slice to set
1869
        ///
1870
        /// # Returns
1871
        ///
1872
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1873
        set_datetimes_slice, DateTime, NaiveDateTime, DataType::DateTime
1874
    }
1875

1876
    impl_set_multi_values_slice! {
1877
        /// Set all UTC instant values via slice
1878
        ///
1879
        /// # Parameters
1880
        ///
1881
        /// * `values` - The UTC instant value slice to set
1882
        ///
1883
        /// # Returns
1884
        ///
1885
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1886
        set_instants_slice, Instant, DateTime<Utc>, DataType::Instant
1887
    }
1888

1889
    impl_set_multi_values_slice! {
1890
        /// Set all big integer values via slice
1891
        ///
1892
        /// # Parameters
1893
        ///
1894
        /// * `values` - The big integer value slice to set
1895
        ///
1896
        /// # Returns
1897
        ///
1898
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1899
        set_bigintegers_slice, BigInteger, BigInt, DataType::BigInteger
1900
    }
1901

1902
    impl_set_multi_values_slice! {
1903
        /// Set all big decimal values via slice
1904
        ///
1905
        /// # Parameters
1906
        ///
1907
        /// * `values` - The big decimal value slice to set
1908
        ///
1909
        /// # Returns
1910
        ///
1911
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1912
        set_bigdecimals_slice, BigDecimal, BigDecimal, DataType::BigDecimal
1913
    }
1914

1915
    impl_set_multi_values_slice! {
1916
        /// Set all isize values via slice
1917
        set_intsizes_slice, IntSize, isize, DataType::IntSize
1918
    }
1919

1920
    impl_set_multi_values_slice! {
1921
        /// Set all usize values via slice
1922
        set_uintsizes_slice, UIntSize, usize, DataType::UIntSize
1923
    }
1924

1925
    impl_set_multi_values_slice! {
1926
        /// Set all Duration values via slice
1927
        set_durations_slice, Duration, Duration, DataType::Duration
1928
    }
1929

1930
    impl_set_multi_values_slice! {
1931
        /// Set all Url values via slice
1932
        set_urls_slice, Url, Url, DataType::Url
1933
    }
1934

1935
    impl_set_multi_values_slice! {
1936
        /// Set all StringMap values via slice
1937
        set_string_maps_slice, StringMap, HashMap<String, String>, DataType::StringMap
1938
    }
1939

1940
    impl_set_multi_values_slice! {
1941
        /// Set all Json values via slice
1942
        set_jsons_slice, Json, serde_json::Value, DataType::Json
1943
    }
1944

1945
    // ========================================================================
1946
    // Set single value operations
1947
    // ========================================================================
1948

1949
    impl_set_single_value! {
1950
        /// Set single boolean value
1951
        ///
1952
        /// # Parameters
1953
        ///
1954
        /// * `value` - The boolean value to set
1955
        ///
1956
        /// # Returns
1957
        ///
1958
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1959
        ///
1960
        /// # Example
1961
        ///
1962
        /// ```rust,ignore
1963
        /// use crate::util::value::MultiValues;
1964
        ///
1965
        /// let mut values = MultiValues::Empty(DataType::Bool);
1966
        /// values.set_bool(true).unwrap();
1967
        /// assert_eq!(values.get_bools().unwrap(), &[true]);
1968
        /// ```
1969
        set_bool, Bool, bool, DataType::Bool
1970
    }
1971

1972
    impl_set_single_value! {
1973
        /// Set single character value
1974
        ///
1975
        /// # Parameters
1976
        ///
1977
        /// * `value` - The character value to set
1978
        ///
1979
        /// # Returns
1980
        ///
1981
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1982
        set_char, Char, char, DataType::Char
1983
    }
1984

1985
    impl_set_single_value! {
1986
        /// Set single int8 value
1987
        ///
1988
        /// # Parameters
1989
        ///
1990
        /// * `value` - The int8 value to set
1991
        ///
1992
        /// # Returns
1993
        ///
1994
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
1995
        set_int8, Int8, i8, DataType::Int8
1996
    }
1997

1998
    impl_set_single_value! {
1999
        /// Set single int16 value
2000
        ///
2001
        /// # Parameters
2002
        ///
2003
        /// * `value` - The int16 value to set
2004
        ///
2005
        /// # Returns
2006
        ///
2007
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2008
        set_int16, Int16, i16, DataType::Int16
2009
    }
2010

2011
    impl_set_single_value! {
2012
        /// Set single int32 value
2013
        ///
2014
        /// # Parameters
2015
        ///
2016
        /// * `value` - The int32 value to set
2017
        ///
2018
        /// # Returns
2019
        ///
2020
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2021
        set_int32, Int32, i32, DataType::Int32
2022
    }
2023

2024
    impl_set_single_value! {
2025
        /// Set single int64 value
2026
        ///
2027
        /// # Parameters
2028
        ///
2029
        /// * `value` - The int64 value to set
2030
        ///
2031
        /// # Returns
2032
        ///
2033
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2034
        set_int64, Int64, i64, DataType::Int64
2035
    }
2036

2037
    impl_set_single_value! {
2038
        /// Set single int128 value
2039
        ///
2040
        /// # Parameters
2041
        ///
2042
        /// * `value` - The int128 value to set
2043
        ///
2044
        /// # Returns
2045
        ///
2046
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2047
        set_int128, Int128, i128, DataType::Int128
2048
    }
2049

2050
    impl_set_single_value! {
2051
        /// Set single uint8 value
2052
        ///
2053
        /// # Parameters
2054
        ///
2055
        /// * `value` - The uint8 value to set
2056
        ///
2057
        /// # Returns
2058
        ///
2059
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2060
        set_uint8, UInt8, u8, DataType::UInt8
2061
    }
2062

2063
    impl_set_single_value! {
2064
        /// Set single uint16 value
2065
        ///
2066
        /// # Parameters
2067
        ///
2068
        /// * `value` - The uint16 value to set
2069
        ///
2070
        /// # Returns
2071
        ///
2072
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2073
        set_uint16, UInt16, u16, DataType::UInt16
2074
    }
2075

2076
    impl_set_single_value! {
2077
        /// Set single uint32 value
2078
        ///
2079
        /// # Parameters
2080
        ///
2081
        /// * `value` - The uint32 value to set
2082
        ///
2083
        /// # Returns
2084
        ///
2085
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2086
        set_uint32, UInt32, u32, DataType::UInt32
2087
    }
2088

2089
    impl_set_single_value! {
2090
        /// Set single uint64 value
2091
        ///
2092
        /// # Parameters
2093
        ///
2094
        /// * `value` - The uint64 value to set
2095
        ///
2096
        /// # Returns
2097
        ///
2098
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2099
        set_uint64, UInt64, u64, DataType::UInt64
2100
    }
2101

2102
    impl_set_single_value! {
2103
        /// Set single uint128 value
2104
        ///
2105
        /// # Parameters
2106
        ///
2107
        /// * `value` - The uint128 value to set
2108
        ///
2109
        /// # Returns
2110
        ///
2111
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2112
        set_uint128, UInt128, u128, DataType::UInt128
2113
    }
2114

2115
    impl_set_single_value! {
2116
        /// Set single float32 value
2117
        ///
2118
        /// # Parameters
2119
        ///
2120
        /// * `value` - The float32 value to set
2121
        ///
2122
        /// # Returns
2123
        ///
2124
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2125
        set_float32, Float32, f32, DataType::Float32
2126
    }
2127

2128
    impl_set_single_value! {
2129
        /// Set single float64 value
2130
        ///
2131
        /// # Parameters
2132
        ///
2133
        /// * `value` - The float64 value to set
2134
        ///
2135
        /// # Returns
2136
        ///
2137
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2138
        set_float64, Float64, f64, DataType::Float64
2139
    }
2140

2141
    impl_set_single_value! {
2142
        /// Set single string value
2143
        ///
2144
        /// # Parameters
2145
        ///
2146
        /// * `value` - The string value to set
2147
        ///
2148
        /// # Returns
2149
        ///
2150
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2151
        ///
2152
        /// # Example
2153
        ///
2154
        /// ```rust,ignore
2155
        /// use crate::util::value::MultiValues;
2156
        ///
2157
        /// let mut values = MultiValues::Empty(DataType::String);
2158
        /// values.set_string("hello".to_string()).unwrap();
2159
        /// assert_eq!(values.get_strings().unwrap(), &["hello"]);
2160
        /// ```
2161
        set_string, String, String, DataType::String
2162
    }
2163

2164
    impl_set_single_value! {
2165
        /// Set single date value
2166
        ///
2167
        /// # Parameters
2168
        ///
2169
        /// * `value` - The date value to set
2170
        ///
2171
        /// # Returns
2172
        ///
2173
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2174
        set_date, Date, NaiveDate, DataType::Date
2175
    }
2176

2177
    impl_set_single_value! {
2178
        /// Set single time value
2179
        ///
2180
        /// # Parameters
2181
        ///
2182
        /// * `value` - The time value to set
2183
        ///
2184
        /// # Returns
2185
        ///
2186
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2187
        set_time, Time, NaiveTime, DataType::Time
2188
    }
2189

2190
    impl_set_single_value! {
2191
        /// Set single datetime value
2192
        ///
2193
        /// # Parameters
2194
        ///
2195
        /// * `value` - The datetime value to set
2196
        ///
2197
        /// # Returns
2198
        ///
2199
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2200
        set_datetime, DateTime, NaiveDateTime, DataType::DateTime
2201
    }
2202

2203
    impl_set_single_value! {
2204
        /// Set single UTC instant value
2205
        ///
2206
        /// # Parameters
2207
        ///
2208
        /// * `value` - The UTC instant value to set
2209
        ///
2210
        /// # Returns
2211
        ///
2212
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2213
        set_instant, Instant, DateTime<Utc>, DataType::Instant
2214
    }
2215

2216
    impl_set_single_value! {
2217
        /// Set single big integer value
2218
        ///
2219
        /// # Parameters
2220
        ///
2221
        /// * `value` - The big integer value to set
2222
        ///
2223
        /// # Returns
2224
        ///
2225
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2226
        set_biginteger, BigInteger, BigInt, DataType::BigInteger
2227
    }
2228

2229
    impl_set_single_value! {
2230
        /// Set single big decimal value
2231
        ///
2232
        /// # Parameters
2233
        ///
2234
        /// * `value` - The big decimal value to set
2235
        ///
2236
        /// # Returns
2237
        ///
2238
        /// If setting succeeds, returns `Ok(())`; otherwise returns an error
2239
        set_bigdecimal, BigDecimal, BigDecimal, DataType::BigDecimal
2240
    }
2241

2242
    impl_set_single_value! {
2243
        /// Set single isize value
2244
        set_intsize, IntSize, isize, DataType::IntSize
2245
    }
2246

2247
    impl_set_single_value! {
2248
        /// Set single usize value
2249
        set_uintsize, UIntSize, usize, DataType::UIntSize
2250
    }
2251

2252
    impl_set_single_value! {
2253
        /// Set single Duration value
2254
        set_duration, Duration, Duration, DataType::Duration
2255
    }
2256

2257
    impl_set_single_value! {
2258
        /// Set single Url value
2259
        set_url, Url, Url, DataType::Url
2260
    }
2261

2262
    impl_set_single_value! {
2263
        /// Set single StringMap value
2264
        set_string_map, StringMap, HashMap<String, String>, DataType::StringMap
2265
    }
2266

2267
    impl_set_single_value! {
2268
        /// Set single Json value
2269
        set_json, Json, serde_json::Value, DataType::Json
2270
    }
2271

2272
    // ========================================================================
2273
    // Add value operations
2274
    // ========================================================================
2275

2276
    impl_add_single_value! {
2277
        /// Add a boolean value
2278
        ///
2279
        /// # Parameters
2280
        ///
2281
        /// * `value` - The boolean value to add
2282
        ///
2283
        /// # Returns
2284
        ///
2285
        /// If types match, returns `Ok(())`; otherwise returns an error
2286
        ///
2287
        /// # Example
2288
        ///
2289
        /// ```rust,ignore
2290
        /// use crate::util::value::MultiValues;
2291
        ///
2292
        /// let mut values = MultiValues::Bool(vec![true]);
2293
        /// values.add_bool(false).unwrap();
2294
        /// assert_eq!(values.count(), 2);
2295
        /// ```
2296
        add_bool, Bool, bool, DataType::Bool
2297
    }
2298

2299
    impl_add_single_value! {
2300
        /// Add a character value
2301
        ///
2302
        /// # Parameters
2303
        ///
2304
        /// * `value` - The character value to add
2305
        ///
2306
        /// # Returns
2307
        ///
2308
        /// If types match, returns `Ok(())`; otherwise returns an error
2309
        add_char, Char, char, DataType::Char
2310
    }
2311

2312
    impl_add_single_value! {
2313
        /// Add an int8 value
2314
        ///
2315
        /// # Parameters
2316
        ///
2317
        /// * `value` - The int8 value to add
2318
        ///
2319
        /// # Returns
2320
        ///
2321
        /// If types match, returns `Ok(())`; otherwise returns an error
2322
        add_int8, Int8, i8, DataType::Int8
2323
    }
2324

2325
    impl_add_single_value! {
2326
        /// Add an int16 value
2327
        ///
2328
        /// # Parameters
2329
        ///
2330
        /// * `value` - The int16 value to add
2331
        ///
2332
        /// # Returns
2333
        ///
2334
        /// If types match, returns `Ok(())`; otherwise returns an error
2335
        add_int16, Int16, i16, DataType::Int16
2336
    }
2337

2338
    impl_add_single_value! {
2339
        /// Add an int32 value
2340
        ///
2341
        /// # Parameters
2342
        ///
2343
        /// * `value` - The int32 value to add
2344
        ///
2345
        /// # Returns
2346
        ///
2347
        /// If types match, returns `Ok(())`; otherwise returns an error
2348
        add_int32, Int32, i32, DataType::Int32
2349
    }
2350

2351
    impl_add_single_value! {
2352
        /// Add an int64 value
2353
        ///
2354
        /// # Parameters
2355
        ///
2356
        /// * `value` - The int64 value to add
2357
        ///
2358
        /// # Returns
2359
        ///
2360
        /// If types match, returns `Ok(())`; otherwise returns an error
2361
        add_int64, Int64, i64, DataType::Int64
2362
    }
2363

2364
    impl_add_single_value! {
2365
        /// Add an int128 value
2366
        ///
2367
        /// # Parameters
2368
        ///
2369
        /// * `value` - The int128 value to add
2370
        ///
2371
        /// # Returns
2372
        ///
2373
        /// If types match, returns `Ok(())`; otherwise returns an error
2374
        add_int128, Int128, i128, DataType::Int128
2375
    }
2376

2377
    impl_add_single_value! {
2378
        /// Add a uint8 value
2379
        ///
2380
        /// # Parameters
2381
        ///
2382
        /// * `value` - The uint8 value to add
2383
        ///
2384
        /// # Returns
2385
        ///
2386
        /// If types match, returns `Ok(())`; otherwise returns an error
2387
        add_uint8, UInt8, u8, DataType::UInt8
2388
    }
2389

2390
    impl_add_single_value! {
2391
        /// Add a uint16 value
2392
        ///
2393
        /// # Parameters
2394
        ///
2395
        /// * `value` - The uint16 value to add
2396
        ///
2397
        /// # Returns
2398
        ///
2399
        /// If types match, returns `Ok(())`; otherwise returns an error
2400
        add_uint16, UInt16, u16, DataType::UInt16
2401
    }
2402

2403
    impl_add_single_value! {
2404
        /// Add a uint32 value
2405
        ///
2406
        /// # Parameters
2407
        ///
2408
        /// * `value` - The uint32 value to add
2409
        ///
2410
        /// # Returns
2411
        ///
2412
        /// If types match, returns `Ok(())`; otherwise returns an error
2413
        add_uint32, UInt32, u32, DataType::UInt32
2414
    }
2415

2416
    impl_add_single_value! {
2417
        /// Add a uint64 value
2418
        ///
2419
        /// # Parameters
2420
        ///
2421
        /// * `value` - The uint64 value to add
2422
        ///
2423
        /// # Returns
2424
        ///
2425
        /// If types match, returns `Ok(())`; otherwise returns an error
2426
        add_uint64, UInt64, u64, DataType::UInt64
2427
    }
2428

2429
    impl_add_single_value! {
2430
        /// Add a uint128 value
2431
        ///
2432
        /// # Parameters
2433
        ///
2434
        /// * `value` - The uint128 value to add
2435
        ///
2436
        /// # Returns
2437
        ///
2438
        /// If types match, returns `Ok(())`; otherwise returns an error
2439
        add_uint128, UInt128, u128, DataType::UInt128
2440
    }
2441

2442
    impl_add_single_value! {
2443
        /// Add a float32 value
2444
        ///
2445
        /// # Parameters
2446
        ///
2447
        /// * `value` - The float32 value to add
2448
        ///
2449
        /// # Returns
2450
        ///
2451
        /// If types match, returns `Ok(())`; otherwise returns an error
2452
        add_float32, Float32, f32, DataType::Float32
2453
    }
2454

2455
    impl_add_single_value! {
2456
        /// Add a float64 value
2457
        ///
2458
        /// # Parameters
2459
        ///
2460
        /// * `value` - The float64 value to add
2461
        ///
2462
        /// # Returns
2463
        ///
2464
        /// If types match, returns `Ok(())`; otherwise returns an error
2465
        add_float64, Float64, f64, DataType::Float64
2466
    }
2467

2468
    impl_add_single_value! {
2469
        /// Add a string
2470
        ///
2471
        /// # Parameters
2472
        ///
2473
        /// * `value` - The string to add
2474
        ///
2475
        /// # Returns
2476
        ///
2477
        /// If types match, returns `Ok(())`; otherwise returns an error
2478
        add_string, String, String, DataType::String
2479
    }
2480

2481
    impl_add_single_value! {
2482
        /// Add a date value
2483
        ///
2484
        /// # Parameters
2485
        ///
2486
        /// * `value` - The date value to add
2487
        ///
2488
        /// # Returns
2489
        ///
2490
        /// If types match, returns `Ok(())`; otherwise returns an error
2491
        add_date, Date, NaiveDate, DataType::Date
2492
    }
2493

2494
    impl_add_single_value! {
2495
        /// Add a time value
2496
        ///
2497
        /// # Parameters
2498
        ///
2499
        /// * `value` - The time value to add
2500
        ///
2501
        /// # Returns
2502
        ///
2503
        /// If types match, returns `Ok(())`; otherwise returns an error
2504
        add_time, Time, NaiveTime, DataType::Time
2505
    }
2506

2507
    impl_add_single_value! {
2508
        /// Add a datetime value
2509
        ///
2510
        /// # Parameters
2511
        ///
2512
        /// * `value` - The datetime value to add
2513
        ///
2514
        /// # Returns
2515
        ///
2516
        /// If types match, returns `Ok(())`; otherwise returns an error
2517
        add_datetime, DateTime, NaiveDateTime, DataType::DateTime
2518
    }
2519

2520
    impl_add_single_value! {
2521
        /// Add a UTC instant value
2522
        ///
2523
        /// # Parameters
2524
        ///
2525
        /// * `value` - The UTC instant value to add
2526
        ///
2527
        /// # Returns
2528
        ///
2529
        /// If types match, returns `Ok(())`; otherwise returns an error
2530
        add_instant, Instant, DateTime<Utc>, DataType::Instant
2531
    }
2532

2533
    impl_add_single_value! {
2534
        /// Add a big integer value
2535
        ///
2536
        /// # Parameters
2537
        ///
2538
        /// * `value` - The big integer value to add
2539
        ///
2540
        /// # Returns
2541
        ///
2542
        /// If types match, returns `Ok(())`; otherwise returns an error
2543
        add_biginteger, BigInteger, BigInt, DataType::BigInteger
2544
    }
2545

2546
    impl_add_single_value! {
2547
        /// Add a big decimal value
2548
        ///
2549
        /// # Parameters
2550
        ///
2551
        /// * `value` - The big decimal value to add
2552
        ///
2553
        /// # Returns
2554
        ///
2555
        /// If types match, returns `Ok(())`; otherwise returns an error
2556
        add_bigdecimal, BigDecimal, BigDecimal, DataType::BigDecimal
2557
    }
2558

2559
    impl_add_single_value! {
2560
        /// Add an isize value
2561
        add_intsize, IntSize, isize, DataType::IntSize
2562
    }
2563

2564
    impl_add_single_value! {
2565
        /// Add a usize value
2566
        add_uintsize, UIntSize, usize, DataType::UIntSize
2567
    }
2568

2569
    impl_add_single_value! {
2570
        /// Add a Duration value
2571
        add_duration, Duration, Duration, DataType::Duration
2572
    }
2573

2574
    impl_add_single_value! {
2575
        /// Add a Url value
2576
        add_url, Url, Url, DataType::Url
2577
    }
2578

2579
    impl_add_single_value! {
2580
        /// Add a StringMap value
2581
        add_string_map, StringMap, HashMap<String, String>, DataType::StringMap
2582
    }
2583

2584
    impl_add_single_value! {
2585
        /// Add a Json value
2586
        add_json, Json, serde_json::Value, DataType::Json
2587
    }
2588

2589
    // ========================================================================
2590
    // Add multiple values operations
2591
    // ========================================================================
2592

2593
    impl_add_multi_values! {
2594
        /// Add multiple boolean values
2595
        ///
2596
        /// # Parameters
2597
        ///
2598
        /// * `values` - The list of boolean values to add
2599
        ///
2600
        /// # Returns
2601
        ///
2602
        /// If types match, returns `Ok(())`; otherwise returns an error
2603
        ///
2604
        /// # Example
2605
        ///
2606
        /// ```rust,ignore
2607
        /// use crate::util::value::MultiValues;
2608
        ///
2609
        /// let mut values = MultiValues::Bool(vec![true]);
2610
        /// values.add_bools(vec![false, true]).unwrap();
2611
        /// assert_eq!(values.get_bools().unwrap(), &[true, false, true]);
2612
        /// ```
2613
        add_bools, Bool, bool, DataType::Bool
2614
    }
2615

2616
    impl_add_multi_values! {
2617
        /// Add multiple character values
2618
        ///
2619
        /// # Parameters
2620
        ///
2621
        /// * `values` - The list of character values to add
2622
        ///
2623
        /// # Returns
2624
        ///
2625
        /// If types match, returns `Ok(())`; otherwise returns an error
2626
        add_chars, Char, char, DataType::Char
2627
    }
2628

2629
    impl_add_multi_values! {
2630
        /// Add multiple int8 values
2631
        ///
2632
        /// # Parameters
2633
        ///
2634
        /// * `values` - The list of int8 values to add
2635
        ///
2636
        /// # Returns
2637
        ///
2638
        /// If types match, returns `Ok(())`; otherwise returns an error
2639
        add_int8s, Int8, i8, DataType::Int8
2640
    }
2641

2642
    impl_add_multi_values! {
2643
        /// Add multiple int16 values
2644
        ///
2645
        /// # Parameters
2646
        ///
2647
        /// * `values` - The list of int16 values to add
2648
        ///
2649
        /// # Returns
2650
        ///
2651
        /// If types match, returns `Ok(())`; otherwise returns an error
2652
        add_int16s, Int16, i16, DataType::Int16
2653
    }
2654

2655
    impl_add_multi_values! {
2656
        /// Add multiple int32 values
2657
        ///
2658
        /// # Parameters
2659
        ///
2660
        /// * `values` - The list of int32 values to add
2661
        ///
2662
        /// # Returns
2663
        ///
2664
        /// If types match, returns `Ok(())`; otherwise returns an error
2665
        add_int32s, Int32, i32, DataType::Int32
2666
    }
2667

2668
    impl_add_multi_values! {
2669
        /// Add multiple int64 values
2670
        ///
2671
        /// # Parameters
2672
        ///
2673
        /// * `values` - The list of int64 values to add
2674
        ///
2675
        /// # Returns
2676
        ///
2677
        /// If types match, returns `Ok(())`; otherwise returns an error
2678
        add_int64s, Int64, i64, DataType::Int64
2679
    }
2680

2681
    impl_add_multi_values! {
2682
        /// Add multiple int128 values
2683
        ///
2684
        /// # Parameters
2685
        ///
2686
        /// * `values` - The list of int128 values to add
2687
        ///
2688
        /// # Returns
2689
        ///
2690
        /// If types match, returns `Ok(())`; otherwise returns an error
2691
        add_int128s, Int128, i128, DataType::Int128
2692
    }
2693

2694
    impl_add_multi_values! {
2695
        /// Add multiple uint8 values
2696
        ///
2697
        /// # Parameters
2698
        ///
2699
        /// * `values` - The list of uint8 values to add
2700
        ///
2701
        /// # Returns
2702
        ///
2703
        /// If types match, returns `Ok(())`; otherwise returns an error
2704
        add_uint8s, UInt8, u8, DataType::UInt8
2705
    }
2706

2707
    impl_add_multi_values! {
2708
        /// Add multiple uint16 values
2709
        ///
2710
        /// # Parameters
2711
        ///
2712
        /// * `values` - The list of uint16 values to add
2713
        ///
2714
        /// # Returns
2715
        ///
2716
        /// If types match, returns `Ok(())`; otherwise returns an error
2717
        add_uint16s, UInt16, u16, DataType::UInt16
2718
    }
2719

2720
    impl_add_multi_values! {
2721
        /// Add multiple uint32 values
2722
        ///
2723
        /// # Parameters
2724
        ///
2725
        /// * `values` - The list of uint32 values to add
2726
        ///
2727
        /// # Returns
2728
        ///
2729
        /// If types match, returns `Ok(())`; otherwise returns an error
2730
        add_uint32s, UInt32, u32, DataType::UInt32
2731
    }
2732

2733
    impl_add_multi_values! {
2734
        /// Add multiple uint64 values
2735
        ///
2736
        /// # Parameters
2737
        ///
2738
        /// * `values` - The list of uint64 values to add
2739
        ///
2740
        /// # Returns
2741
        ///
2742
        /// If types match, returns `Ok(())`; otherwise returns an error
2743
        add_uint64s, UInt64, u64, DataType::UInt64
2744
    }
2745

2746
    impl_add_multi_values! {
2747
        /// Add multiple uint128 values
2748
        ///
2749
        /// # Parameters
2750
        ///
2751
        /// * `values` - The list of uint128 values to add
2752
        ///
2753
        /// # Returns
2754
        ///
2755
        /// If types match, returns `Ok(())`; otherwise returns an error
2756
        add_uint128s, UInt128, u128, DataType::UInt128
2757
    }
2758

2759
    impl_add_multi_values! {
2760
        /// Add multiple float32 values
2761
        ///
2762
        /// # Parameters
2763
        ///
2764
        /// * `values` - The list of float32 values to add
2765
        ///
2766
        /// # Returns
2767
        ///
2768
        /// If types match, returns `Ok(())`; otherwise returns an error
2769
        add_float32s, Float32, f32, DataType::Float32
2770
    }
2771

2772
    impl_add_multi_values! {
2773
        /// Add multiple float64 values
2774
        ///
2775
        /// # Parameters
2776
        ///
2777
        /// * `values` - The list of float64 values to add
2778
        ///
2779
        /// # Returns
2780
        ///
2781
        /// If types match, returns `Ok(())`; otherwise returns an error
2782
        add_float64s, Float64, f64, DataType::Float64
2783
    }
2784

2785
    impl_add_multi_values! {
2786
        /// Add multiple string values
2787
        ///
2788
        /// # Parameters
2789
        ///
2790
        /// * `values` - The list of string values to add
2791
        ///
2792
        /// # Returns
2793
        ///
2794
        /// If types match, returns `Ok(())`; otherwise returns an error
2795
        ///
2796
        /// # Example
2797
        ///
2798
        /// ```rust,ignore
2799
        /// use crate::util::value::MultiValues;
2800
        ///
2801
        /// let mut values = MultiValues::String(vec!["hello".to_string()]);
2802
        /// values.add_strings(vec!["world".to_string(), "rust".to_string()]).unwrap();
2803
        /// assert_eq!(values.get_strings().unwrap(), &["hello", "world", "rust"]);
2804
        /// ```
2805
        add_strings, String, String, DataType::String
2806
    }
2807

2808
    impl_add_multi_values! {
2809
        /// Add multiple date values
2810
        ///
2811
        /// # Parameters
2812
        ///
2813
        /// * `values` - The list of date values to add
2814
        ///
2815
        /// # Returns
2816
        ///
2817
        /// If types match, returns `Ok(())`; otherwise returns an error
2818
        add_dates, Date, NaiveDate, DataType::Date
2819
    }
2820

2821
    impl_add_multi_values! {
2822
        /// Add multiple time values
2823
        ///
2824
        /// # Parameters
2825
        ///
2826
        /// * `values` - The list of time values to add
2827
        ///
2828
        /// # Returns
2829
        ///
2830
        /// If types match, returns `Ok(())`; otherwise returns an error
2831
        add_times, Time, NaiveTime, DataType::Time
2832
    }
2833

2834
    impl_add_multi_values! {
2835
        /// Add multiple datetime values
2836
        ///
2837
        /// # Parameters
2838
        ///
2839
        /// * `values` - The list of datetime values to add
2840
        ///
2841
        /// # Returns
2842
        ///
2843
        /// If types match, returns `Ok(())`; otherwise returns an error
2844
        add_datetimes, DateTime, NaiveDateTime, DataType::DateTime
2845
    }
2846

2847
    impl_add_multi_values! {
2848
        /// Add multiple UTC instant values
2849
        ///
2850
        /// # Parameters
2851
        ///
2852
        /// * `values` - The list of UTC instant values to add
2853
        ///
2854
        /// # Returns
2855
        ///
2856
        /// If types match, returns `Ok(())`; otherwise returns an error
2857
        add_instants, Instant, DateTime<Utc>, DataType::Instant
2858
    }
2859

2860
    impl_add_multi_values! {
2861
        /// Add multiple big integer values
2862
        ///
2863
        /// # Parameters
2864
        ///
2865
        /// * `values` - The list of big integer values to add
2866
        ///
2867
        /// # Returns
2868
        ///
2869
        /// If types match, returns `Ok(())`; otherwise returns an error
2870
        add_bigintegers, BigInteger, BigInt, DataType::BigInteger
2871
    }
2872

2873
    impl_add_multi_values! {
2874
        /// Add multiple big decimal values
2875
        ///
2876
        /// # Parameters
2877
        ///
2878
        /// * `values` - The list of big decimal values to add
2879
        ///
2880
        /// # Returns
2881
        ///
2882
        /// If types match, returns `Ok(())`; otherwise returns an error
2883
        add_bigdecimals, BigDecimal, BigDecimal, DataType::BigDecimal
2884
    }
2885

2886
    impl_add_multi_values! {
2887
        /// Add multiple isize values
2888
        add_intsizes, IntSize, isize, DataType::IntSize
2889
    }
2890

2891
    impl_add_multi_values! {
2892
        /// Add multiple usize values
2893
        add_uintsizes, UIntSize, usize, DataType::UIntSize
2894
    }
2895

2896
    impl_add_multi_values! {
2897
        /// Add multiple Duration values
2898
        add_durations, Duration, Duration, DataType::Duration
2899
    }
2900

2901
    impl_add_multi_values! {
2902
        /// Add multiple Url values
2903
        add_urls, Url, Url, DataType::Url
2904
    }
2905

2906
    impl_add_multi_values! {
2907
        /// Add multiple StringMap values
2908
        add_string_maps, StringMap, HashMap<String, String>, DataType::StringMap
2909
    }
2910

2911
    impl_add_multi_values! {
2912
        /// Add multiple Json values
2913
        add_jsons, Json, serde_json::Value, DataType::Json
2914
    }
2915

2916
    // ========================================================================
2917
    // Add multiple values via slice operations
2918
    // ========================================================================
2919

2920
    impl_add_multi_values_slice! {
2921
        /// Add multiple boolean values via slice
2922
        ///
2923
        /// # Parameters
2924
        ///
2925
        /// * `values` - The boolean value slice to add
2926
        ///
2927
        /// # Returns
2928
        ///
2929
        /// If types match, returns `Ok(())`; otherwise returns an error
2930
        add_bools_slice, Bool, bool, DataType::Bool
2931
    }
2932

2933
    impl_add_multi_values_slice! {
2934
        /// Add multiple character values via slice
2935
        ///
2936
        /// # Parameters
2937
        ///
2938
        /// * `values` - The character value slice to add
2939
        ///
2940
        /// # Returns
2941
        ///
2942
        /// If types match, returns `Ok(())`; otherwise returns an error
2943
        add_chars_slice, Char, char, DataType::Char
2944
    }
2945

2946
    impl_add_multi_values_slice! {
2947
        /// Add multiple int8 values via slice
2948
        ///
2949
        /// # Parameters
2950
        ///
2951
        /// * `values` - The int8 value slice to add
2952
        ///
2953
        /// # Returns
2954
        ///
2955
        /// If types match, returns `Ok(())`; otherwise returns an error
2956
        add_int8s_slice, Int8, i8, DataType::Int8
2957
    }
2958

2959
    impl_add_multi_values_slice! {
2960
        /// Add multiple int16 values via slice
2961
        ///
2962
        /// # Parameters
2963
        ///
2964
        /// * `values` - The int16 value slice to add
2965
        ///
2966
        /// # Returns
2967
        ///
2968
        /// If types match, returns `Ok(())`; otherwise returns an error
2969
        add_int16s_slice, Int16, i16, DataType::Int16
2970
    }
2971

2972
    impl_add_multi_values_slice! {
2973
        /// Add multiple int32 values via slice
2974
        ///
2975
        /// # Parameters
2976
        ///
2977
        /// * `values` - The int32 value slice to add
2978
        ///
2979
        /// # Returns
2980
        ///
2981
        /// If types match, returns `Ok(())`; otherwise returns an error
2982
        add_int32s_slice, Int32, i32, DataType::Int32
2983
    }
2984

2985
    impl_add_multi_values_slice! {
2986
        /// Add multiple int64 values via slice
2987
        ///
2988
        /// # Parameters
2989
        ///
2990
        /// * `values` - The int64 value slice to add
2991
        ///
2992
        /// # Returns
2993
        ///
2994
        /// If types match, returns `Ok(())`; otherwise returns an error
2995
        add_int64s_slice, Int64, i64, DataType::Int64
2996
    }
2997

2998
    impl_add_multi_values_slice! {
2999
        /// Add multiple int128 values via slice
3000
        ///
3001
        /// # Parameters
3002
        ///
3003
        /// * `values` - The int128 value slice to add
3004
        ///
3005
        /// # Returns
3006
        ///
3007
        /// If types match, returns `Ok(())`; otherwise returns an error
3008
        add_int128s_slice, Int128, i128, DataType::Int128
3009
    }
3010

3011
    impl_add_multi_values_slice! {
3012
        /// Add multiple uint8 values via slice
3013
        ///
3014
        /// # Parameters
3015
        ///
3016
        /// * `values` - The uint8 value slice to add
3017
        ///
3018
        /// # Returns
3019
        ///
3020
        /// If types match, returns `Ok(())`; otherwise returns an error
3021
        add_uint8s_slice, UInt8, u8, DataType::UInt8
3022
    }
3023

3024
    impl_add_multi_values_slice! {
3025
        /// Add multiple uint16 values via slice
3026
        ///
3027
        /// # Parameters
3028
        ///
3029
        /// * `values` - The uint16 value slice to add
3030
        ///
3031
        /// # Returns
3032
        ///
3033
        /// If types match, returns `Ok(())`; otherwise returns an error
3034
        add_uint16s_slice, UInt16, u16, DataType::UInt16
3035
    }
3036

3037
    impl_add_multi_values_slice! {
3038
        /// Add multiple uint32 values via slice
3039
        ///
3040
        /// # Parameters
3041
        ///
3042
        /// * `values` - The uint32 value slice to add
3043
        ///
3044
        /// # Returns
3045
        ///
3046
        /// If types match, returns `Ok(())`; otherwise returns an error
3047
        add_uint32s_slice, UInt32, u32, DataType::UInt32
3048
    }
3049

3050
    impl_add_multi_values_slice! {
3051
        /// Add multiple uint64 values via slice
3052
        ///
3053
        /// # Parameters
3054
        ///
3055
        /// * `values` - The uint64 value slice to add
3056
        ///
3057
        /// # Returns
3058
        ///
3059
        /// If types match, returns `Ok(())`; otherwise returns an error
3060
        add_uint64s_slice, UInt64, u64, DataType::UInt64
3061
    }
3062

3063
    impl_add_multi_values_slice! {
3064
        /// Add multiple uint128 values via slice
3065
        ///
3066
        /// # Parameters
3067
        ///
3068
        /// * `values` - The uint128 value slice to add
3069
        ///
3070
        /// # Returns
3071
        ///
3072
        /// If types match, returns `Ok(())`; otherwise returns an error
3073
        add_uint128s_slice, UInt128, u128, DataType::UInt128
3074
    }
3075

3076
    impl_add_multi_values_slice! {
3077
        /// Add multiple float32 values via slice
3078
        ///
3079
        /// # Parameters
3080
        ///
3081
        /// * `values` - The float32 value slice to add
3082
        ///
3083
        /// # Returns
3084
        ///
3085
        /// If types match, returns `Ok(())`; otherwise returns an error
3086
        add_float32s_slice, Float32, f32, DataType::Float32
3087
    }
3088

3089
    impl_add_multi_values_slice! {
3090
        /// Add multiple float64 values via slice
3091
        ///
3092
        /// # Parameters
3093
        ///
3094
        /// * `values` - The float64 value slice to add
3095
        ///
3096
        /// # Returns
3097
        ///
3098
        /// If types match, returns `Ok(())`; otherwise returns an error
3099
        add_float64s_slice, Float64, f64, DataType::Float64
3100
    }
3101

3102
    impl_add_multi_values_slice! {
3103
        /// Add multiple strings via slice
3104
        ///
3105
        /// # Parameters
3106
        ///
3107
        /// * `values` - The string slice to add
3108
        ///
3109
        /// # Returns
3110
        ///
3111
        /// If types match, returns `Ok(())`; otherwise returns an error
3112
        add_strings_slice, String, String, DataType::String
3113
    }
3114

3115
    impl_add_multi_values_slice! {
3116
        /// Add multiple date values via slice
3117
        ///
3118
        /// # Parameters
3119
        ///
3120
        /// * `values` - The date value slice to add
3121
        ///
3122
        /// # Returns
3123
        ///
3124
        /// If types match, returns `Ok(())`; otherwise returns an error
3125
        add_dates_slice, Date, NaiveDate, DataType::Date
3126
    }
3127

3128
    impl_add_multi_values_slice! {
3129
        /// Add multiple time values via slice
3130
        ///
3131
        /// # Parameters
3132
        ///
3133
        /// * `values` - The time value slice to add
3134
        ///
3135
        /// # Returns
3136
        ///
3137
        /// If types match, returns `Ok(())`; otherwise returns an error
3138
        add_times_slice, Time, NaiveTime, DataType::Time
3139
    }
3140

3141
    impl_add_multi_values_slice! {
3142
        /// Add multiple datetime values via slice
3143
        ///
3144
        /// # Parameters
3145
        ///
3146
        /// * `values` - The datetime value slice to add
3147
        ///
3148
        /// # Returns
3149
        ///
3150
        /// If types match, returns `Ok(())`; otherwise returns an error
3151
        add_datetimes_slice, DateTime, NaiveDateTime, DataType::DateTime
3152
    }
3153

3154
    impl_add_multi_values_slice! {
3155
        /// Add multiple UTC instant values via slice
3156
        ///
3157
        /// # Parameters
3158
        ///
3159
        /// * `values` - The UTC instant value slice to add
3160
        ///
3161
        /// # Returns
3162
        ///
3163
        /// If types match, returns `Ok(())`; otherwise returns an error
3164
        add_instants_slice, Instant, DateTime<Utc>, DataType::Instant
3165
    }
3166

3167
    impl_add_multi_values_slice! {
3168
        /// Add multiple big integer values via slice
3169
        ///
3170
        /// # Parameters
3171
        ///
3172
        /// * `values` - The big integer value slice to add
3173
        ///
3174
        /// # Returns
3175
        ///
3176
        /// If types match, returns `Ok(())`; otherwise returns an error
3177
        add_bigintegers_slice, BigInteger, BigInt, DataType::BigInteger
3178
    }
3179

3180
    impl_add_multi_values_slice! {
3181
        /// Add multiple big decimal values via slice
3182
        ///
3183
        /// # Parameters
3184
        ///
3185
        /// * `values` - The big decimal value slice to add
3186
        ///
3187
        /// # Returns
3188
        ///
3189
        /// If types match, returns `Ok(())`; otherwise returns an error
3190
        add_bigdecimals_slice, BigDecimal, BigDecimal, DataType::BigDecimal
3191
    }
3192

3193
    impl_add_multi_values_slice! {
3194
        /// Add multiple isize values via slice
3195
        add_intsizes_slice, IntSize, isize, DataType::IntSize
3196
    }
3197

3198
    impl_add_multi_values_slice! {
3199
        /// Add multiple usize values via slice
3200
        add_uintsizes_slice, UIntSize, usize, DataType::UIntSize
3201
    }
3202

3203
    impl_add_multi_values_slice! {
3204
        /// Add multiple Duration values via slice
3205
        add_durations_slice, Duration, Duration, DataType::Duration
3206
    }
3207

3208
    impl_add_multi_values_slice! {
3209
        /// Add multiple Url values via slice
3210
        add_urls_slice, Url, Url, DataType::Url
3211
    }
3212

3213
    impl_add_multi_values_slice! {
3214
        /// Add multiple StringMap values via slice
3215
        add_string_maps_slice, StringMap, HashMap<String, String>, DataType::StringMap
3216
    }
3217

3218
    impl_add_multi_values_slice! {
3219
        /// Add multiple Json values via slice
3220
        add_jsons_slice, Json, serde_json::Value, DataType::Json
3221
    }
3222

3223
    /// Merge another multiple values
3224
    ///
3225
    /// Append all values from another multiple values to the current multiple values
3226
    ///
3227
    /// # Parameters
3228
    ///
3229
    /// * `other` - The multiple values to merge
3230
    ///
3231
    /// # Returns
3232
    ///
3233
    /// If types match, returns `Ok(())`; otherwise returns an error
3234
    ///
3235
    /// # Example
3236
    ///
3237
    /// ```rust,ignore
3238
    /// use crate::util::value::MultiValues;
3239
    ///
3240
    /// let mut a = MultiValues::Int32(vec![1, 2]);
3241
    /// let b = MultiValues::Int32(vec![3, 4]);
3242
    /// a.merge(&b).unwrap();
3243
    /// assert_eq!(a.get_int32s().unwrap(), &[1, 2, 3, 4]);
3244
    /// ```
3245
    pub fn merge(&mut self, other: &MultiValues) -> ValueResult<()> {
60✔
3246
        if self.data_type() != other.data_type() {
60✔
3247
            return Err(ValueError::TypeMismatch {
2✔
3248
                expected: self.data_type(),
2✔
3249
                actual: other.data_type(),
2✔
3250
            });
2✔
3251
        }
58✔
3252

3253
        match (self, other) {
58✔
3254
            (MultiValues::Bool(v), MultiValues::Bool(o)) => v.extend_from_slice(o),
2✔
3255
            (MultiValues::Char(v), MultiValues::Char(o)) => v.extend_from_slice(o),
2✔
3256
            (MultiValues::Int8(v), MultiValues::Int8(o)) => v.extend_from_slice(o),
2✔
3257
            (MultiValues::Int16(v), MultiValues::Int16(o)) => v.extend_from_slice(o),
2✔
3258
            (MultiValues::Int32(v), MultiValues::Int32(o)) => v.extend_from_slice(o),
2✔
3259
            (MultiValues::Int64(v), MultiValues::Int64(o)) => v.extend_from_slice(o),
2✔
3260
            (MultiValues::Int128(v), MultiValues::Int128(o)) => v.extend_from_slice(o),
2✔
3261
            (MultiValues::UInt8(v), MultiValues::UInt8(o)) => v.extend_from_slice(o),
2✔
3262
            (MultiValues::UInt16(v), MultiValues::UInt16(o)) => v.extend_from_slice(o),
2✔
3263
            (MultiValues::UInt32(v), MultiValues::UInt32(o)) => v.extend_from_slice(o),
2✔
3264
            (MultiValues::UInt64(v), MultiValues::UInt64(o)) => v.extend_from_slice(o),
2✔
3265
            (MultiValues::UInt128(v), MultiValues::UInt128(o)) => v.extend_from_slice(o),
2✔
3266
            (MultiValues::Float32(v), MultiValues::Float32(o)) => v.extend_from_slice(o),
2✔
3267
            (MultiValues::Float64(v), MultiValues::Float64(o)) => v.extend_from_slice(o),
2✔
3268
            (MultiValues::String(v), MultiValues::String(o)) => v.extend_from_slice(o),
2✔
3269
            (MultiValues::Date(v), MultiValues::Date(o)) => v.extend_from_slice(o),
2✔
3270
            (MultiValues::Time(v), MultiValues::Time(o)) => v.extend_from_slice(o),
2✔
3271
            (MultiValues::DateTime(v), MultiValues::DateTime(o)) => v.extend_from_slice(o),
2✔
3272
            (MultiValues::Instant(v), MultiValues::Instant(o)) => v.extend_from_slice(o),
2✔
3273
            (MultiValues::BigInteger(v), MultiValues::BigInteger(o)) => v.extend_from_slice(o),
2✔
3274
            (MultiValues::BigDecimal(v), MultiValues::BigDecimal(o)) => v.extend_from_slice(o),
2✔
3275
            (MultiValues::IntSize(v), MultiValues::IntSize(o)) => v.extend_from_slice(o),
2✔
3276
            (MultiValues::UIntSize(v), MultiValues::UIntSize(o)) => v.extend_from_slice(o),
×
3277
            (MultiValues::Duration(v), MultiValues::Duration(o)) => v.extend_from_slice(o),
2✔
3278
            (MultiValues::Url(v), MultiValues::Url(o)) => v.extend_from_slice(o),
×
3279
            (MultiValues::StringMap(v), MultiValues::StringMap(o)) => v.extend(o.iter().cloned()),
×
3280
            (MultiValues::Json(v), MultiValues::Json(o)) => v.extend(o.iter().cloned()),
2✔
3281
            (MultiValues::Empty(_), _) => {}
10✔
3282
            _ => unreachable!(),
×
3283
        }
3284

3285
        Ok(())
58✔
3286
    }
60✔
3287
}
3288

3289
impl Default for MultiValues {
3290
    fn default() -> Self {
2✔
3291
        MultiValues::Empty(DataType::String)
2✔
3292
    }
2✔
3293
}
3294

3295
impl From<Value> for MultiValues {
3296
    fn from(value: Value) -> Self {
64✔
3297
        match value {
64✔
3298
            Value::Empty(dt) => MultiValues::Empty(dt),
2✔
3299
            Value::Bool(v) => MultiValues::Bool(vec![v]),
2✔
3300
            Value::Char(v) => MultiValues::Char(vec![v]),
2✔
3301
            Value::Int8(v) => MultiValues::Int8(vec![v]),
2✔
3302
            Value::Int16(v) => MultiValues::Int16(vec![v]),
2✔
3303
            Value::Int32(v) => MultiValues::Int32(vec![v]),
6✔
3304
            Value::Int64(v) => MultiValues::Int64(vec![v]),
2✔
3305
            Value::Int128(v) => MultiValues::Int128(vec![v]),
2✔
3306
            Value::UInt8(v) => MultiValues::UInt8(vec![v]),
2✔
3307
            Value::UInt16(v) => MultiValues::UInt16(vec![v]),
2✔
3308
            Value::UInt32(v) => MultiValues::UInt32(vec![v]),
2✔
3309
            Value::UInt64(v) => MultiValues::UInt64(vec![v]),
2✔
3310
            Value::UInt128(v) => MultiValues::UInt128(vec![v]),
2✔
3311
            Value::Float32(v) => MultiValues::Float32(vec![v]),
2✔
3312
            Value::Float64(v) => MultiValues::Float64(vec![v]),
2✔
3313
            Value::String(v) => MultiValues::String(vec![v]),
2✔
3314
            Value::Date(v) => MultiValues::Date(vec![v]),
2✔
3315
            Value::Time(v) => MultiValues::Time(vec![v]),
2✔
3316
            Value::DateTime(v) => MultiValues::DateTime(vec![v]),
2✔
3317
            Value::Instant(v) => MultiValues::Instant(vec![v]),
2✔
3318
            Value::BigInteger(v) => MultiValues::BigInteger(vec![v]),
4✔
3319
            Value::BigDecimal(v) => MultiValues::BigDecimal(vec![v]),
4✔
3320
            Value::IntSize(v) => MultiValues::IntSize(vec![v]),
2✔
3321
            Value::UIntSize(v) => MultiValues::UIntSize(vec![v]),
2✔
3322
            Value::Duration(v) => MultiValues::Duration(vec![v]),
2✔
3323
            Value::Url(v) => MultiValues::Url(vec![v]),
2✔
3324
            Value::StringMap(v) => MultiValues::StringMap(vec![v]),
2✔
3325
            Value::Json(v) => MultiValues::Json(vec![v]),
2✔
3326
        }
3327
    }
64✔
3328
}
3329

3330
// ============================================================================
3331
// Internal generic conversion traits (private, not exported, to avoid polluting
3332
// the standard type namespace).
3333
// ============================================================================
3334

3335
/// Internal trait: used to extract multiple values from MultiValues
3336
///
3337
/// This trait is used for internal implementation and cross-crate usage
3338
#[doc(hidden)]
3339
pub trait MultiValuesGetter<T> {
3340
    fn get_values(&self) -> ValueResult<Vec<T>>;
3341
}
3342

3343
/// Internal trait: used to extract the first value from MultiValues
3344
///
3345
/// This trait is used for internal implementation and cross-crate usage
3346
#[doc(hidden)]
3347
pub trait MultiValuesFirstGetter<T> {
3348
    fn get_first_value(&self) -> ValueResult<T>;
3349
}
3350

3351
/// Internal trait: used to set specific types in MultiValues
3352
///
3353
/// This trait is used for internal implementation and cross-crate usage
3354
#[doc(hidden)]
3355
pub trait MultiValuesSetter<T> {
3356
    fn set_values(&mut self, values: Vec<T>) -> ValueResult<()>;
3357
}
3358

3359
/// Internal dispatch trait: dispatches Vec<T>, &[T], T to optimal set path
3360
#[doc(hidden)]
3361
pub trait MultiValuesSetArg<'a> {
3362
    /// Element type
3363
    type Item: 'a + Clone;
3364

3365
    fn apply(self, target: &mut MultiValues) -> ValueResult<()>;
3366
}
3367

3368
/// Internal trait: used to set specific types in MultiValues via slice
3369
///
3370
/// This trait is used for internal implementation and cross-crate usage
3371
#[doc(hidden)]
3372
pub trait MultiValuesSetterSlice<T> {
3373
    fn set_values_slice(&mut self, values: &[T]) -> ValueResult<()>;
3374
}
3375

3376
/// Internal trait: used to set a single value in MultiValues
3377
///
3378
/// This trait is used for internal implementation and cross-crate usage
3379
#[doc(hidden)]
3380
pub trait MultiValuesSingleSetter<T> {
3381
    fn set_single_value(&mut self, value: T) -> ValueResult<()>;
3382
}
3383

3384
/// Internal trait: used to add a single value to MultiValues
3385
///
3386
/// This trait is used for internal implementation and cross-crate usage
3387
#[doc(hidden)]
3388
pub trait MultiValuesAdder<T> {
3389
    fn add_value(&mut self, value: T) -> ValueResult<()>;
3390
}
3391

3392
/// Internal trait: used to add multiple values to MultiValues
3393
///
3394
/// This trait is used for internal implementation and cross-crate usage
3395
#[doc(hidden)]
3396
pub trait MultiValuesMultiAdder<T> {
3397
    fn add_values(&mut self, values: Vec<T>) -> ValueResult<()>;
3398
}
3399

3400
/// Internal dispatch trait: dispatches T / Vec<T> / &[T] to optimal add path
3401
#[doc(hidden)]
3402
pub trait MultiValuesAddArg<'a> {
3403
    /// Element type
3404
    type Item: 'a + Clone;
3405

3406
    fn apply_add(self, target: &mut MultiValues) -> ValueResult<()>;
3407
}
3408

3409
/// Internal trait: used to append multiple values to MultiValues via slice
3410
/// (calls add_[xxx]s_slice by type)
3411
#[doc(hidden)]
3412
pub(crate) trait MultiValuesMultiAdderSlice<T> {
3413
    fn add_values_slice(&mut self, values: &[T]) -> ValueResult<()>;
3414
}
3415

3416
/// Internal trait: used to create MultiValues from Vec<T>
3417
///
3418
/// This trait is not exported in mod.rs, only used for internal implementation,
3419
/// to avoid polluting the standard type namespace
3420
#[doc(hidden)]
3421
pub(crate) trait MultiValuesConstructor<T> {
3422
    fn from_vec(values: Vec<T>) -> Self;
3423
}
3424

3425
// ============================================================================
3426
// Internal trait implementations (simplified using macros)
3427
// ============================================================================
3428

3429
macro_rules! impl_multi_value_traits {
3430
    ($type:ty, $variant:ident, $data_type:expr) => {
3431
        impl MultiValuesGetter<$type> for MultiValues {
3432
            fn get_values(&self) -> ValueResult<Vec<$type>> {
62✔
3433
                match self {
62✔
3434
                    MultiValues::$variant(v) => Ok(v.clone()),
54✔
3435
                    MultiValues::Empty(_) => Ok(Vec::new()),
6✔
3436
                    _ => Err(ValueError::TypeMismatch {
2✔
3437
                        expected: $data_type,
2✔
3438
                        actual: self.data_type(),
2✔
3439
                    }),
2✔
3440
                }
3441
            }
62✔
3442
        }
3443

3444
        impl MultiValuesFirstGetter<$type> for MultiValues {
3445
            fn get_first_value(&self) -> ValueResult<$type> {
40✔
3446
                match self {
38✔
3447
                    MultiValues::$variant(v) if !v.is_empty() => Ok(v[0].clone()),
38✔
3448
                    MultiValues::$variant(_) | MultiValues::Empty(_) => Err(ValueError::NoValue),
2✔
3449
                    _ => Err(ValueError::TypeMismatch {
2✔
3450
                        expected: $data_type,
2✔
3451
                        actual: self.data_type(),
2✔
3452
                    }),
2✔
3453
                }
3454
            }
40✔
3455
        }
3456

3457
        impl MultiValuesSetter<$type> for MultiValues {
3458
            fn set_values(&mut self, values: Vec<$type>) -> ValueResult<()> {
70✔
3459
                *self = MultiValues::$variant(values);
70✔
3460
                Ok(())
70✔
3461
            }
70✔
3462
        }
3463

3464
        // Generic From implementation for SetParam is at the top level, not
3465
        // repeated here for specific types.
3466

3467
        impl MultiValuesSetterSlice<$type> for MultiValues {
3468
            fn set_values_slice(&mut self, values: &[$type]) -> ValueResult<()> {
16✔
3469
                // Equivalent to set_[xxx]s_slice: replace entire list with slice
3470
                *self = MultiValues::$variant(values.to_vec());
16✔
3471
                Ok(())
16✔
3472
            }
16✔
3473
        }
3474

3475
        impl MultiValuesSingleSetter<$type> for MultiValues {
3476
            fn set_single_value(&mut self, value: $type) -> ValueResult<()> {
26✔
3477
                *self = MultiValues::$variant(vec![value]);
26✔
3478
                Ok(())
26✔
3479
            }
26✔
3480
        }
3481

3482
        impl MultiValuesAdder<$type> for MultiValues {
3483
            fn add_value(&mut self, value: $type) -> ValueResult<()> {
60✔
3484
                match self {
8✔
3485
                    MultiValues::$variant(v) => {
46✔
3486
                        v.push(value);
46✔
3487
                        Ok(())
46✔
3488
                    }
3489
                    MultiValues::Empty(dt) if *dt == $data_type => {
8✔
3490
                        *self = MultiValues::$variant(vec![value]);
8✔
3491
                        Ok(())
8✔
3492
                    }
3493
                    _ => Err(ValueError::TypeMismatch {
6✔
3494
                        expected: $data_type,
6✔
3495
                        actual: self.data_type(),
6✔
3496
                    }),
6✔
3497
                }
3498
            }
60✔
3499
        }
3500

3501
        // Three types of implementations for local dispatch trait
3502
        impl<'a> MultiValuesSetArg<'a> for Vec<$type> {
3503
            type Item = $type;
3504

3505
            fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
58✔
3506
                <MultiValues as MultiValuesSetter<$type>>::set_values(target, self)
58✔
3507
            }
58✔
3508
        }
3509

3510
        impl<'a> MultiValuesSetArg<'a> for &'a [$type]
3511
        where
3512
            $type: Clone,
3513
        {
3514
            type Item = $type;
3515

3516
            fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
16✔
3517
                <MultiValues as MultiValuesSetterSlice<$type>>::set_values_slice(target, self)
16✔
3518
            }
16✔
3519
        }
3520

3521
        impl<'a> MultiValuesSetArg<'a> for $type {
3522
            type Item = $type;
3523

3524
            fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
24✔
3525
                <MultiValues as MultiValuesSingleSetter<$type>>::set_single_value(target, self)
24✔
3526
            }
24✔
3527
        }
3528

3529
        impl MultiValuesMultiAdder<$type> for MultiValues {
3530
            fn add_values(&mut self, values: Vec<$type>) -> ValueResult<()> {
40✔
3531
                match self {
10✔
3532
                    MultiValues::$variant(v) => {
26✔
3533
                        v.extend(values);
26✔
3534
                        Ok(())
26✔
3535
                    }
3536
                    MultiValues::Empty(dt) if *dt == $data_type => {
10✔
3537
                        *self = MultiValues::$variant(values);
10✔
3538
                        Ok(())
10✔
3539
                    }
3540
                    _ => Err(ValueError::TypeMismatch {
4✔
3541
                        expected: $data_type,
4✔
3542
                        actual: self.data_type(),
4✔
3543
                    }),
4✔
3544
                }
3545
            }
40✔
3546
        }
3547

3548
        impl MultiValuesMultiAdderSlice<$type> for MultiValues {
3549
            fn add_values_slice(&mut self, values: &[$type]) -> ValueResult<()> {
14✔
3550
                match self {
4✔
3551
                    MultiValues::$variant(v) => {
6✔
3552
                        v.extend_from_slice(values);
6✔
3553
                        Ok(())
6✔
3554
                    }
3555
                    MultiValues::Empty(dt) if *dt == $data_type => {
4✔
3556
                        *self = MultiValues::$variant(values.to_vec());
4✔
3557
                        Ok(())
4✔
3558
                    }
3559
                    _ => Err(ValueError::TypeMismatch {
4✔
3560
                        expected: $data_type,
4✔
3561
                        actual: self.data_type(),
4✔
3562
                    }),
4✔
3563
                }
3564
            }
14✔
3565
        }
3566

3567
        // add dispatch: T / Vec<T> / &[T]
3568
        impl<'a> MultiValuesAddArg<'a> for $type {
3569
            type Item = $type;
3570

3571
            fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
58✔
3572
                <MultiValues as MultiValuesAdder<$type>>::add_value(target, self)
58✔
3573
            }
58✔
3574
        }
3575

3576
        impl<'a> MultiValuesAddArg<'a> for Vec<$type> {
3577
            type Item = $type;
3578

3579
            fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
32✔
3580
                <MultiValues as MultiValuesMultiAdder<$type>>::add_values(target, self)
32✔
3581
            }
32✔
3582
        }
3583

3584
        impl<'a> MultiValuesAddArg<'a> for &'a [$type]
3585
        where
3586
            $type: Clone,
3587
        {
3588
            type Item = $type;
3589

3590
            fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
14✔
3591
                <MultiValues as MultiValuesMultiAdderSlice<$type>>::add_values_slice(target, self)
14✔
3592
            }
14✔
3593
        }
3594

3595
        impl MultiValuesConstructor<$type> for MultiValues {
3596
            fn from_vec(values: Vec<$type>) -> Self {
16✔
3597
                MultiValues::$variant(values)
16✔
3598
            }
16✔
3599
        }
3600
    };
3601
}
3602

3603
// Implementation for Copy types
3604
impl_multi_value_traits!(bool, Bool, DataType::Bool);
3605
impl_multi_value_traits!(char, Char, DataType::Char);
3606
impl_multi_value_traits!(i8, Int8, DataType::Int8);
3607
impl_multi_value_traits!(i16, Int16, DataType::Int16);
3608
impl_multi_value_traits!(i32, Int32, DataType::Int32);
3609
impl_multi_value_traits!(i64, Int64, DataType::Int64);
3610
impl_multi_value_traits!(i128, Int128, DataType::Int128);
3611
impl_multi_value_traits!(u8, UInt8, DataType::UInt8);
3612
impl_multi_value_traits!(u16, UInt16, DataType::UInt16);
3613
impl_multi_value_traits!(u32, UInt32, DataType::UInt32);
3614
impl_multi_value_traits!(u64, UInt64, DataType::UInt64);
3615
impl_multi_value_traits!(u128, UInt128, DataType::UInt128);
3616
impl_multi_value_traits!(f32, Float32, DataType::Float32);
3617
impl_multi_value_traits!(f64, Float64, DataType::Float64);
3618
impl_multi_value_traits!(String, String, DataType::String);
3619
impl_multi_value_traits!(NaiveDate, Date, DataType::Date);
3620
impl_multi_value_traits!(NaiveTime, Time, DataType::Time);
3621
impl_multi_value_traits!(NaiveDateTime, DateTime, DataType::DateTime);
3622
impl_multi_value_traits!(DateTime<Utc>, Instant, DataType::Instant);
3623
impl_multi_value_traits!(BigInt, BigInteger, DataType::BigInteger);
3624
impl_multi_value_traits!(BigDecimal, BigDecimal, DataType::BigDecimal);
3625
impl_multi_value_traits!(isize, IntSize, DataType::IntSize);
3626
impl_multi_value_traits!(usize, UIntSize, DataType::UIntSize);
3627
impl_multi_value_traits!(Duration, Duration, DataType::Duration);
3628
impl_multi_value_traits!(Url, Url, DataType::Url);
3629
impl_multi_value_traits!(HashMap<String, String>, StringMap, DataType::StringMap);
3630
impl_multi_value_traits!(serde_json::Value, Json, DataType::Json);
3631

3632
// Convenience adaptation: &str supported as input type for String
3633
impl MultiValuesSetArg<'_> for &str {
3634
    type Item = String;
3635

3636
    fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
2✔
3637
        <MultiValues as MultiValuesSingleSetter<String>>::set_single_value(target, self.to_string())
2✔
3638
    }
2✔
3639
}
3640

3641
impl MultiValuesSetArg<'_> for Vec<&str> {
3642
    type Item = String;
3643

3644
    fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
6✔
3645
        let owned: Vec<String> = self.into_iter().map(|s| s.to_string()).collect();
20✔
3646
        <MultiValues as MultiValuesSetter<String>>::set_values(target, owned)
6✔
3647
    }
6✔
3648
}
3649

3650
impl<'b> MultiValuesSetArg<'_> for &'b [&'b str] {
3651
    type Item = String;
3652

3653
    fn apply(self, target: &mut MultiValues) -> ValueResult<()> {
6✔
3654
        let owned: Vec<String> = self.iter().map(|s| (*s).to_string()).collect();
16✔
3655
        <MultiValues as MultiValuesSetter<String>>::set_values(target, owned)
6✔
3656
    }
6✔
3657
}
3658

3659
impl MultiValuesAddArg<'_> for &str {
3660
    type Item = String;
3661

3662
    fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
2✔
3663
        <MultiValues as MultiValuesAdder<String>>::add_value(target, self.to_string())
2✔
3664
    }
2✔
3665
}
3666

3667
impl MultiValuesAddArg<'_> for Vec<&str> {
3668
    type Item = String;
3669

3670
    fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
4✔
3671
        let owned: Vec<String> = self.into_iter().map(|s| s.to_string()).collect();
10✔
3672
        <MultiValues as MultiValuesMultiAdder<String>>::add_values(target, owned)
4✔
3673
    }
4✔
3674
}
3675

3676
impl<'b> MultiValuesAddArg<'_> for &'b [&'b str] {
3677
    type Item = String;
3678

3679
    fn apply_add(self, target: &mut MultiValues) -> ValueResult<()> {
4✔
3680
        let owned: Vec<String> = self.iter().map(|s| (*s).to_string()).collect();
10✔
3681
        <MultiValues as MultiValuesMultiAdder<String>>::add_values(target, owned)
4✔
3682
    }
4✔
3683
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc