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