use qubit_datatype::DataType;
use crate::ValueRef;
macro_rules! define_view {
(; $(([$($cfg:meta),*], $variant:ident, $type:ty, $data_type:expr, $materialization:ident, $json_class:ident, $number_projection:ident, $value_doc:literal, $multi_doc:literal $(, $_wire:tt)*)),+ $(,)?) => {
#[must_use]
#[non_exhaustive]
#[derive(Debug, Clone, Copy)]
pub enum MultiValuesRef<'a> {
Unset(#[doc = "Declared source type."] DataType),
$(
$(#[$cfg])*
#[doc = $multi_doc]
$variant(#[doc = "Borrowed or copied source payload."] &'a [$type]),
)+
}
impl<'a> MultiValuesRef<'a> {
#[must_use = "the declared element type should be inspected"]
#[inline(always)]
pub fn data_type(self) -> DataType {
match self {
Self::Unset(data_type) => data_type,
$($(#[$cfg])* Self::$variant(_) => $data_type,)+
}
}
#[must_use]
#[inline(always)]
pub fn len(self) -> usize {
match self {
Self::Unset(_) => 0,
$($(#[$cfg])* Self::$variant(values) => values.len(),)+
}
}
#[must_use]
#[inline(always)]
pub fn is_empty(self) -> bool { self.len() == 0 }
#[must_use]
#[inline(always)]
pub fn get(self, index: usize) -> Option<ValueRef<'a>> {
match self {
Self::Unset(_) => None,
$($(#[$cfg])* Self::$variant(values) => values.get(index)
.map(|value| ValueRef::$variant(value_view_payload!($variant, $number_projection, value))),)+
}
}
}
};
}
for_each_value_type!(define_view);