Skip to main content

qubit_value/multi_values/
multi_values_converters.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
11//! Internal conversion and interoperability implementations for `MultiValues`.
12//!
13//! This module keeps generic conversion logic (`to`, `to_list`, `to_value`, etc.)
14//! while dispatch traits are implemented in dedicated `multi_values_*` modules.
15
16use qubit_datatype::{
17    DataConversionError,
18    DataConversionOptions,
19    DataConvertTo,
20    DataConverter,
21    DataConverters,
22    DataListConversionError,
23    DataType,
24    ScalarStringDataConverters,
25};
26
27use crate::value_error::{
28    ValueError,
29    ValueResult,
30};
31use crate::{
32    IntoValueDefault,
33    Value,
34};
35
36use super::multi_values::MultiValues;
37
38// ============================================================================
39// Inherent conversion APIs and `Value` interop
40// ============================================================================
41
42/// Maps a shared single-value conversion error into `ValueError`.
43///
44/// # Parameters
45///
46/// * `error` - Error returned by `DataConverter`.
47///
48/// # Returns
49///
50/// Returns the corresponding `ValueError` variant.
51fn map_data_conversion_error(error: DataConversionError) -> ValueError {
52    match error {
53        DataConversionError::NoValue => ValueError::NoValue,
54        DataConversionError::ConversionFailed { from, to } => {
55            ValueError::ConversionFailed { from, to }
56        }
57        DataConversionError::ConversionError(message) => ValueError::ConversionError(message),
58        DataConversionError::JsonSerializationError(message) => {
59            ValueError::JsonSerializationError(message)
60        }
61        DataConversionError::JsonDeserializationError(message) => {
62            ValueError::JsonDeserializationError(message)
63        }
64    }
65}
66
67/// Maps a shared batch conversion error into `ValueError`.
68///
69/// # Parameters
70///
71/// * `error` - Error returned by `DataConverters`.
72///
73/// # Returns
74///
75/// Returns a `ValueError::ConversionError` whose message includes the failing
76/// source element index and the underlying conversion error.
77#[inline]
78fn map_data_list_conversion_error(error: DataListConversionError) -> ValueError {
79    let source = map_data_conversion_error(error.source);
80    ValueError::ConversionError(format!(
81        "Cannot convert value at index {}: {}",
82        error.index, source
83    ))
84}
85
86/// Converts the first item from a batch converter using conversion options.
87///
88/// # Type Parameters
89///
90/// * `T` - Target type.
91/// * `I` - Iterator type wrapped by `DataConverters`.
92///
93/// # Parameters
94///
95/// * `values` - Batch converter containing source values.
96/// * `options` - Conversion options forwarded to `qubit_datatype`.
97///
98/// # Returns
99///
100/// Returns the converted first value.
101///
102/// # Errors
103///
104/// Returns `ValueError::NoValue` for empty sources or the mapped single-value
105/// conversion error for an invalid first source value.
106#[inline]
107fn convert_first_with<'a, T, I>(
108    values: DataConverters<'a, I>,
109    options: &DataConversionOptions,
110) -> ValueResult<T>
111where
112    DataConverter<'a>: DataConvertTo<T>,
113    I: Iterator,
114    I::Item: Into<DataConverter<'a>>,
115{
116    values
117        .to_first_with(options)
118        .map_err(map_data_conversion_error)
119}
120
121/// Converts every item from a batch converter using conversion options.
122///
123/// # Type Parameters
124///
125/// * `T` - Target element type.
126/// * `I` - Iterator type wrapped by `DataConverters`.
127///
128/// # Parameters
129///
130/// * `values` - Batch converter containing source values.
131/// * `options` - Conversion options forwarded to `qubit_datatype`.
132///
133/// # Returns
134///
135/// Returns converted values in the original order.
136///
137/// # Errors
138///
139/// Returns a mapped batch conversion error containing the failing source index.
140#[inline]
141fn convert_values_with<'a, T, I>(
142    values: DataConverters<'a, I>,
143    options: &DataConversionOptions,
144) -> ValueResult<Vec<T>>
145where
146    DataConverter<'a>: DataConvertTo<T>,
147    I: Iterator,
148    I::Item: Into<DataConverter<'a>>,
149{
150    values
151        .to_vec_with(options)
152        .map_err(map_data_list_conversion_error)
153}
154
155impl MultiValues {
156    /// Converts the first stored value to `T`.
157    ///
158    /// Unlike [`Self::get_first`], this method uses shared `DataConverter`
159    /// conversion rules instead of strict type matching. For example, a stored
160    /// `String("1")` can be converted to `bool`.
161    ///
162    /// # Type Parameters
163    ///
164    /// * `T` - Target type.
165    ///
166    /// # Returns
167    ///
168    /// The converted first value.
169    ///
170    /// # Errors
171    ///
172    /// Returns [`ValueError::NoValue`] when no value is stored, or a conversion
173    /// error when the first value cannot be converted to `T`.
174    #[inline]
175    pub fn to<T>(&self) -> ValueResult<T>
176    where
177        for<'a> DataConverter<'a>: DataConvertTo<T>,
178    {
179        self.to_with(&DataConversionOptions::default())
180    }
181
182    /// Converts the first stored value to `T`, or returns `default` when no
183    /// value is stored.
184    #[inline]
185    pub fn to_or<T>(&self, default: impl IntoValueDefault<T>) -> ValueResult<T>
186    where
187        for<'a> DataConverter<'a>: DataConvertTo<T>,
188    {
189        match self.to() {
190            Err(ValueError::NoValue) => Ok(default.into_value_default()),
191            result => result,
192        }
193    }
194
195    /// Converts the first stored value to `T` using conversion options.
196    ///
197    /// A `MultiValues::String` containing exactly one string is treated as a
198    /// scalar string source, so collection options can split it before taking
199    /// the first converted item. Multiple stored string values are treated as
200    /// an already-materialized list and are converted element by element.
201    ///
202    /// # Type Parameters
203    ///
204    /// * `T` - Target type.
205    ///
206    /// # Parameters
207    ///
208    /// * `options` - Conversion options forwarded to `qubit_datatype`.
209    ///
210    /// # Returns
211    ///
212    /// The converted first value.
213    ///
214    /// # Errors
215    ///
216    /// Returns [`ValueError::NoValue`] when no value is stored, or a conversion
217    /// error when the first value cannot be converted to `T`.
218    #[inline]
219    pub fn to_with<T>(&self, options: &DataConversionOptions) -> ValueResult<T>
220    where
221        for<'a> DataConverter<'a>: DataConvertTo<T>,
222    {
223        match self {
224            MultiValues::Empty(_) => Err(ValueError::NoValue),
225            MultiValues::Bool(v) => convert_first_with(DataConverters::from(v), options),
226            MultiValues::Char(v) => convert_first_with(DataConverters::from(v), options),
227            MultiValues::Int8(v) => convert_first_with(DataConverters::from(v), options),
228            MultiValues::Int16(v) => convert_first_with(DataConverters::from(v), options),
229            MultiValues::Int32(v) => convert_first_with(DataConverters::from(v), options),
230            MultiValues::Int64(v) => convert_first_with(DataConverters::from(v), options),
231            MultiValues::Int128(v) => convert_first_with(DataConverters::from(v), options),
232            MultiValues::UInt8(v) => convert_first_with(DataConverters::from(v), options),
233            MultiValues::UInt16(v) => convert_first_with(DataConverters::from(v), options),
234            MultiValues::UInt32(v) => convert_first_with(DataConverters::from(v), options),
235            MultiValues::UInt64(v) => convert_first_with(DataConverters::from(v), options),
236            MultiValues::UInt128(v) => convert_first_with(DataConverters::from(v), options),
237            MultiValues::IntSize(v) => convert_first_with(DataConverters::from(v), options),
238            MultiValues::UIntSize(v) => convert_first_with(DataConverters::from(v), options),
239            MultiValues::Float32(v) => convert_first_with(DataConverters::from(v), options),
240            MultiValues::Float64(v) => convert_first_with(DataConverters::from(v), options),
241            MultiValues::BigInteger(v) => convert_first_with(DataConverters::from(v), options),
242            MultiValues::BigDecimal(v) => convert_first_with(DataConverters::from(v), options),
243            MultiValues::String(v) if v.len() == 1 => {
244                ScalarStringDataConverters::from(v[0].as_str())
245                    .to_first_with(options)
246                    .map_err(map_data_conversion_error)
247            }
248            MultiValues::String(v) => convert_first_with(DataConverters::from(v), options),
249            MultiValues::Date(v) => convert_first_with(DataConverters::from(v), options),
250            MultiValues::Time(v) => convert_first_with(DataConverters::from(v), options),
251            MultiValues::DateTime(v) => convert_first_with(DataConverters::from(v), options),
252            MultiValues::Instant(v) => convert_first_with(DataConverters::from(v), options),
253            MultiValues::Duration(v) => convert_first_with(DataConverters::from(v), options),
254            MultiValues::Url(v) => convert_first_with(DataConverters::from(v), options),
255            MultiValues::StringMap(v) => convert_first_with(DataConverters::from(v), options),
256            MultiValues::Json(v) => convert_first_with(DataConverters::from(v), options),
257        }
258    }
259
260    /// Converts the first stored value to `T` using conversion options, or
261    /// returns `default` when no value is stored.
262    #[inline]
263    pub fn to_or_with<T>(
264        &self,
265        default: impl IntoValueDefault<T>,
266        options: &DataConversionOptions,
267    ) -> ValueResult<T>
268    where
269        for<'a> DataConverter<'a>: DataConvertTo<T>,
270    {
271        match self.to_with(options) {
272            Err(ValueError::NoValue) => Ok(default.into_value_default()),
273            result => result,
274        }
275    }
276
277    /// Converts all stored values to `T`.
278    ///
279    /// Unlike [`Self::get`], this method uses shared `DataConverter` conversion
280    /// rules for every element instead of strict type matching. Empty values
281    /// return an empty vector.
282    ///
283    /// # Type Parameters
284    ///
285    /// * `T` - Target element type.
286    ///
287    /// # Returns
288    ///
289    /// A vector containing all converted values in the original order.
290    ///
291    /// # Errors
292    ///
293    /// Returns the first conversion error encountered while converting an
294    /// element.
295    pub fn to_list<T>(&self) -> ValueResult<Vec<T>>
296    where
297        for<'a> DataConverter<'a>: DataConvertTo<T>,
298    {
299        self.to_list_with(&DataConversionOptions::default())
300    }
301
302    /// Converts all stored values to `T`, or returns `default` when the
303    /// converted list is empty.
304    #[inline]
305    pub fn to_list_or<T>(&self, default: impl IntoValueDefault<Vec<T>>) -> ValueResult<Vec<T>>
306    where
307        for<'a> DataConverter<'a>: DataConvertTo<T>,
308    {
309        let values = self.to_list()?;
310        if values.is_empty() {
311            Ok(default.into_value_default())
312        } else {
313            Ok(values)
314        }
315    }
316
317    /// Converts all stored values to `T` using conversion options.
318    ///
319    /// A `MultiValues::String` containing exactly one string is treated as a
320    /// scalar string source, so collection options can split it into items.
321    /// Multiple stored string values are treated as an already-materialized
322    /// list and are converted element by element.
323    ///
324    /// # Type Parameters
325    ///
326    /// * `T` - Target element type.
327    ///
328    /// # Parameters
329    ///
330    /// * `options` - Conversion options forwarded to `qubit_datatype`.
331    ///
332    /// # Returns
333    ///
334    /// A vector containing all converted values in the original order.
335    ///
336    /// # Errors
337    ///
338    /// Returns the first conversion error encountered while converting an
339    /// element.
340    pub fn to_list_with<T>(&self, options: &DataConversionOptions) -> ValueResult<Vec<T>>
341    where
342        for<'a> DataConverter<'a>: DataConvertTo<T>,
343    {
344        match self {
345            MultiValues::Empty(_) => Ok(Vec::new()),
346            MultiValues::Bool(v) => convert_values_with(DataConverters::from(v), options),
347            MultiValues::Char(v) => convert_values_with(DataConverters::from(v), options),
348            MultiValues::Int8(v) => convert_values_with(DataConverters::from(v), options),
349            MultiValues::Int16(v) => convert_values_with(DataConverters::from(v), options),
350            MultiValues::Int32(v) => convert_values_with(DataConverters::from(v), options),
351            MultiValues::Int64(v) => convert_values_with(DataConverters::from(v), options),
352            MultiValues::Int128(v) => convert_values_with(DataConverters::from(v), options),
353            MultiValues::UInt8(v) => convert_values_with(DataConverters::from(v), options),
354            MultiValues::UInt16(v) => convert_values_with(DataConverters::from(v), options),
355            MultiValues::UInt32(v) => convert_values_with(DataConverters::from(v), options),
356            MultiValues::UInt64(v) => convert_values_with(DataConverters::from(v), options),
357            MultiValues::UInt128(v) => convert_values_with(DataConverters::from(v), options),
358            MultiValues::IntSize(v) => convert_values_with(DataConverters::from(v), options),
359            MultiValues::UIntSize(v) => convert_values_with(DataConverters::from(v), options),
360            MultiValues::Float32(v) => convert_values_with(DataConverters::from(v), options),
361            MultiValues::Float64(v) => convert_values_with(DataConverters::from(v), options),
362            MultiValues::BigInteger(v) => convert_values_with(DataConverters::from(v), options),
363            MultiValues::BigDecimal(v) => convert_values_with(DataConverters::from(v), options),
364            MultiValues::String(v) if v.len() == 1 => {
365                ScalarStringDataConverters::from(v[0].as_str())
366                    .to_vec_with(options)
367                    .map_err(map_data_list_conversion_error)
368            }
369            MultiValues::String(v) => convert_values_with(DataConverters::from(v), options),
370            MultiValues::Date(v) => convert_values_with(DataConverters::from(v), options),
371            MultiValues::Time(v) => convert_values_with(DataConverters::from(v), options),
372            MultiValues::DateTime(v) => convert_values_with(DataConverters::from(v), options),
373            MultiValues::Instant(v) => convert_values_with(DataConverters::from(v), options),
374            MultiValues::Duration(v) => convert_values_with(DataConverters::from(v), options),
375            MultiValues::Url(v) => convert_values_with(DataConverters::from(v), options),
376            MultiValues::StringMap(v) => convert_values_with(DataConverters::from(v), options),
377            MultiValues::Json(v) => convert_values_with(DataConverters::from(v), options),
378        }
379    }
380
381    /// Converts all stored values to `T` using conversion options, or returns
382    /// `default` when the converted list is empty.
383    #[inline]
384    pub fn to_list_or_with<T>(
385        &self,
386        default: impl IntoValueDefault<Vec<T>>,
387        options: &DataConversionOptions,
388    ) -> ValueResult<Vec<T>>
389    where
390        for<'a> DataConverter<'a>: DataConvertTo<T>,
391    {
392        let values = self.to_list_with(options)?;
393        if values.is_empty() {
394            Ok(default.into_value_default())
395        } else {
396            Ok(values)
397        }
398    }
399
400    /// Convert to a single [`Value`] by taking the first element.
401    ///
402    /// If there is no element, returns `Value::Empty(self.data_type())`.
403    ///
404    /// # Returns
405    ///
406    /// Returns the first element wrapped as [`Value`], or an empty value
407    /// preserving the current data type.
408    pub fn to_value(&self) -> Value {
409        match self {
410            MultiValues::Empty(dt) => Value::Empty(*dt),
411            MultiValues::Bool(v) => v
412                .first()
413                .copied()
414                .map(Value::Bool)
415                .unwrap_or(Value::Empty(DataType::Bool)),
416            MultiValues::Char(v) => v
417                .first()
418                .copied()
419                .map(Value::Char)
420                .unwrap_or(Value::Empty(DataType::Char)),
421            MultiValues::Int8(v) => v
422                .first()
423                .copied()
424                .map(Value::Int8)
425                .unwrap_or(Value::Empty(DataType::Int8)),
426            MultiValues::Int16(v) => v
427                .first()
428                .copied()
429                .map(Value::Int16)
430                .unwrap_or(Value::Empty(DataType::Int16)),
431            MultiValues::Int32(v) => v
432                .first()
433                .copied()
434                .map(Value::Int32)
435                .unwrap_or(Value::Empty(DataType::Int32)),
436            MultiValues::Int64(v) => v
437                .first()
438                .copied()
439                .map(Value::Int64)
440                .unwrap_or(Value::Empty(DataType::Int64)),
441            MultiValues::Int128(v) => v
442                .first()
443                .copied()
444                .map(Value::Int128)
445                .unwrap_or(Value::Empty(DataType::Int128)),
446            MultiValues::UInt8(v) => v
447                .first()
448                .copied()
449                .map(Value::UInt8)
450                .unwrap_or(Value::Empty(DataType::UInt8)),
451            MultiValues::UInt16(v) => v
452                .first()
453                .copied()
454                .map(Value::UInt16)
455                .unwrap_or(Value::Empty(DataType::UInt16)),
456            MultiValues::UInt32(v) => v
457                .first()
458                .copied()
459                .map(Value::UInt32)
460                .unwrap_or(Value::Empty(DataType::UInt32)),
461            MultiValues::UInt64(v) => v
462                .first()
463                .copied()
464                .map(Value::UInt64)
465                .unwrap_or(Value::Empty(DataType::UInt64)),
466            MultiValues::UInt128(v) => v
467                .first()
468                .copied()
469                .map(Value::UInt128)
470                .unwrap_or(Value::Empty(DataType::UInt128)),
471            MultiValues::IntSize(v) => v
472                .first()
473                .copied()
474                .map(Value::IntSize)
475                .unwrap_or(Value::Empty(DataType::IntSize)),
476            MultiValues::UIntSize(v) => v
477                .first()
478                .copied()
479                .map(Value::UIntSize)
480                .unwrap_or(Value::Empty(DataType::UIntSize)),
481            MultiValues::Float32(v) => v
482                .first()
483                .copied()
484                .map(Value::Float32)
485                .unwrap_or(Value::Empty(DataType::Float32)),
486            MultiValues::Float64(v) => v
487                .first()
488                .copied()
489                .map(Value::Float64)
490                .unwrap_or(Value::Empty(DataType::Float64)),
491            MultiValues::BigInteger(v) => v
492                .first()
493                .cloned()
494                .map(Value::BigInteger)
495                .unwrap_or(Value::Empty(DataType::BigInteger)),
496            MultiValues::BigDecimal(v) => v
497                .first()
498                .cloned()
499                .map(Value::BigDecimal)
500                .unwrap_or(Value::Empty(DataType::BigDecimal)),
501            MultiValues::String(v) => v
502                .first()
503                .cloned()
504                .map(Value::String)
505                .unwrap_or(Value::Empty(DataType::String)),
506            MultiValues::Date(v) => v
507                .first()
508                .copied()
509                .map(Value::Date)
510                .unwrap_or(Value::Empty(DataType::Date)),
511            MultiValues::Time(v) => v
512                .first()
513                .copied()
514                .map(Value::Time)
515                .unwrap_or(Value::Empty(DataType::Time)),
516            MultiValues::DateTime(v) => v
517                .first()
518                .copied()
519                .map(Value::DateTime)
520                .unwrap_or(Value::Empty(DataType::DateTime)),
521            MultiValues::Instant(v) => v
522                .first()
523                .copied()
524                .map(Value::Instant)
525                .unwrap_or(Value::Empty(DataType::Instant)),
526            MultiValues::Duration(v) => v
527                .first()
528                .copied()
529                .map(Value::Duration)
530                .unwrap_or(Value::Empty(DataType::Duration)),
531            MultiValues::Url(v) => v
532                .first()
533                .cloned()
534                .map(Value::Url)
535                .unwrap_or(Value::Empty(DataType::Url)),
536            MultiValues::StringMap(v) => v
537                .first()
538                .cloned()
539                .map(Value::StringMap)
540                .unwrap_or(Value::Empty(DataType::StringMap)),
541            MultiValues::Json(v) => v
542                .first()
543                .cloned()
544                .map(Value::Json)
545                .unwrap_or(Value::Empty(DataType::Json)),
546        }
547    }
548
549    /// Merge another multiple values
550    ///
551    /// Append all values from another multiple values to the current multiple values
552    ///
553    /// # Parameters
554    ///
555    /// * `other` - The multiple values to merge
556    ///
557    /// # Returns
558    ///
559    /// If types match, returns `Ok(())`; otherwise returns an error
560    ///
561    /// # Example
562    ///
563    /// ```rust
564    /// use qubit_value::MultiValues;
565    ///
566    /// let mut a = MultiValues::Int32(vec![1, 2]);
567    /// let b = MultiValues::Int32(vec![3, 4]);
568    /// a.merge(&b).unwrap();
569    /// assert_eq!(a.get_int32s().unwrap(), &[1, 2, 3, 4]);
570    /// ```
571    pub fn merge(&mut self, other: &MultiValues) -> ValueResult<()> {
572        if self.data_type() != other.data_type() {
573            return Err(ValueError::TypeMismatch {
574                expected: self.data_type(),
575                actual: other.data_type(),
576            });
577        }
578        if other.count() == 0 {
579            return Ok(());
580        }
581
582        match (self, other) {
583            (MultiValues::Bool(v), MultiValues::Bool(o)) => v.extend_from_slice(o),
584            (MultiValues::Char(v), MultiValues::Char(o)) => v.extend_from_slice(o),
585            (MultiValues::Int8(v), MultiValues::Int8(o)) => v.extend_from_slice(o),
586            (MultiValues::Int16(v), MultiValues::Int16(o)) => v.extend_from_slice(o),
587            (MultiValues::Int32(v), MultiValues::Int32(o)) => v.extend_from_slice(o),
588            (MultiValues::Int64(v), MultiValues::Int64(o)) => v.extend_from_slice(o),
589            (MultiValues::Int128(v), MultiValues::Int128(o)) => v.extend_from_slice(o),
590            (MultiValues::UInt8(v), MultiValues::UInt8(o)) => v.extend_from_slice(o),
591            (MultiValues::UInt16(v), MultiValues::UInt16(o)) => v.extend_from_slice(o),
592            (MultiValues::UInt32(v), MultiValues::UInt32(o)) => v.extend_from_slice(o),
593            (MultiValues::UInt64(v), MultiValues::UInt64(o)) => v.extend_from_slice(o),
594            (MultiValues::UInt128(v), MultiValues::UInt128(o)) => v.extend_from_slice(o),
595            (MultiValues::Float32(v), MultiValues::Float32(o)) => v.extend_from_slice(o),
596            (MultiValues::Float64(v), MultiValues::Float64(o)) => v.extend_from_slice(o),
597            (MultiValues::String(v), MultiValues::String(o)) => v.extend_from_slice(o),
598            (MultiValues::Date(v), MultiValues::Date(o)) => v.extend_from_slice(o),
599            (MultiValues::Time(v), MultiValues::Time(o)) => v.extend_from_slice(o),
600            (MultiValues::DateTime(v), MultiValues::DateTime(o)) => v.extend_from_slice(o),
601            (MultiValues::Instant(v), MultiValues::Instant(o)) => v.extend_from_slice(o),
602            (MultiValues::BigInteger(v), MultiValues::BigInteger(o)) => v.extend_from_slice(o),
603            (MultiValues::BigDecimal(v), MultiValues::BigDecimal(o)) => v.extend_from_slice(o),
604            (MultiValues::IntSize(v), MultiValues::IntSize(o)) => v.extend_from_slice(o),
605            (MultiValues::UIntSize(v), MultiValues::UIntSize(o)) => v.extend_from_slice(o),
606            (MultiValues::Duration(v), MultiValues::Duration(o)) => v.extend_from_slice(o),
607            (MultiValues::Url(v), MultiValues::Url(o)) => v.extend_from_slice(o),
608            (MultiValues::StringMap(v), MultiValues::StringMap(o)) => v.extend(o.iter().cloned()),
609            (MultiValues::Json(v), MultiValues::Json(o)) => v.extend(o.iter().cloned()),
610            (slot @ MultiValues::Empty(_), other_values) => *slot = other_values.clone(),
611            _ => unreachable!(),
612        }
613
614        Ok(())
615    }
616}
617
618impl Default for MultiValues {
619    #[inline]
620    fn default() -> Self {
621        MultiValues::Empty(DataType::String)
622    }
623}
624
625impl From<Value> for MultiValues {
626    fn from(value: Value) -> Self {
627        match value {
628            Value::Empty(dt) => MultiValues::Empty(dt),
629            Value::Bool(v) => MultiValues::Bool(vec![v]),
630            Value::Char(v) => MultiValues::Char(vec![v]),
631            Value::Int8(v) => MultiValues::Int8(vec![v]),
632            Value::Int16(v) => MultiValues::Int16(vec![v]),
633            Value::Int32(v) => MultiValues::Int32(vec![v]),
634            Value::Int64(v) => MultiValues::Int64(vec![v]),
635            Value::Int128(v) => MultiValues::Int128(vec![v]),
636            Value::UInt8(v) => MultiValues::UInt8(vec![v]),
637            Value::UInt16(v) => MultiValues::UInt16(vec![v]),
638            Value::UInt32(v) => MultiValues::UInt32(vec![v]),
639            Value::UInt64(v) => MultiValues::UInt64(vec![v]),
640            Value::UInt128(v) => MultiValues::UInt128(vec![v]),
641            Value::Float32(v) => MultiValues::Float32(vec![v]),
642            Value::Float64(v) => MultiValues::Float64(vec![v]),
643            Value::String(v) => MultiValues::String(vec![v]),
644            Value::Date(v) => MultiValues::Date(vec![v]),
645            Value::Time(v) => MultiValues::Time(vec![v]),
646            Value::DateTime(v) => MultiValues::DateTime(vec![v]),
647            Value::Instant(v) => MultiValues::Instant(vec![v]),
648            Value::BigInteger(v) => MultiValues::BigInteger(vec![v]),
649            Value::BigDecimal(v) => MultiValues::BigDecimal(vec![v]),
650            Value::IntSize(v) => MultiValues::IntSize(vec![v]),
651            Value::UIntSize(v) => MultiValues::UIntSize(vec![v]),
652            Value::Duration(v) => MultiValues::Duration(vec![v]),
653            Value::Url(v) => MultiValues::Url(vec![v]),
654            Value::StringMap(v) => MultiValues::StringMap(vec![v]),
655            Value::Json(v) => MultiValues::Json(vec![v]),
656        }
657    }
658}