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