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