use serde::Serialize;
use crate::MultiValues;
use crate::multi_values::MultiValuesRepr;
use super::WireDataTypeV1;
macro_rules! define_collection_wire_ref {
(
$(
(
[$($cfg:meta),*],
[$($scalar_attr:meta),*],
[$($collection_attr:meta),*],
$variant:ident,
$type:ty,
$tag:literal
)
),+ $(,)?
) => {
#[derive(Clone, Copy, Serialize)]
pub(in crate::value_wire) enum CollectionWireRef<'a> {
#[serde(rename = "unset")]
Unset(
/// Declared element type of the unset collection.
WireDataTypeV1,
),
$(
$(#[$cfg])*
$(#[$collection_attr])*
#[doc = concat!("Borrowed `", $tag, "` collection payload.")]
#[serde(rename = $tag)]
$variant(
#[doc = concat!("Stored `", $tag, "` collection values.")]
&'a Vec<$type>,
),
)+
}
impl<'a> From<&'a MultiValues> for CollectionWireRef<'a> {
fn from(values: &'a MultiValues) -> Self {
match &values.repr {
MultiValuesRepr::Unset(data_type) => Self::Unset((*data_type).into()),
$(
$(#[$cfg])*
MultiValuesRepr::$variant(values) => Self::$variant(values),
)+
}
}
}
};
}
for_each_wire_type!(define_collection_wire_ref);