mod subtype;
mod values;
use std::{fmt, io};
pub use self::{subtype::Subtype, values::Values};
pub enum Array<'a> {
Int8(Box<dyn Values<'a, i8> + 'a>),
UInt8(Box<dyn Values<'a, u8> + 'a>),
Int16(Box<dyn Values<'a, i16> + 'a>),
UInt16(Box<dyn Values<'a, u16> + 'a>),
Int32(Box<dyn Values<'a, i32> + 'a>),
UInt32(Box<dyn Values<'a, u32> + 'a>),
Float(Box<dyn Values<'a, f32> + 'a>),
}
impl<'a> Array<'a> {
pub fn subtype(&self) -> Subtype {
match self {
Array::Int8(_) => Subtype::Int8,
Array::UInt8(_) => Subtype::UInt8,
Array::Int16(_) => Subtype::Int16,
Array::UInt16(_) => Subtype::UInt16,
Array::Int32(_) => Subtype::Int32,
Array::UInt32(_) => Subtype::UInt32,
Array::Float(_) => Subtype::Float,
}
}
}
impl<'a> fmt::Debug for Array<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Int8(values) => f.debug_list().entries(values.iter()).finish(),
Self::UInt8(values) => f.debug_list().entries(values.iter()).finish(),
Self::Int16(values) => f.debug_list().entries(values.iter()).finish(),
Self::UInt16(values) => f.debug_list().entries(values.iter()).finish(),
Self::Int32(values) => f.debug_list().entries(values.iter()).finish(),
Self::UInt32(values) => f.debug_list().entries(values.iter()).finish(),
Self::Float(values) => f.debug_list().entries(values.iter()).finish(),
}
}
}
impl<'a> TryFrom<Array<'a>> for crate::alignment::record_buf::data::field::value::Array {
type Error = io::Error;
fn try_from(array: Array<'a>) -> Result<Self, Self::Error> {
match array {
Array::Int8(values) => values.iter().collect::<Result<_, _>>().map(Self::Int8),
Array::UInt8(values) => values.iter().collect::<Result<_, _>>().map(Self::UInt8),
Array::Int16(values) => values.iter().collect::<Result<_, _>>().map(Self::Int16),
Array::UInt16(values) => values.iter().collect::<Result<_, _>>().map(Self::UInt16),
Array::Int32(values) => values.iter().collect::<Result<_, _>>().map(Self::Int32),
Array::UInt32(values) => values.iter().collect::<Result<_, _>>().map(Self::UInt32),
Array::Float(values) => values.iter().collect::<Result<_, _>>().map(Self::Float),
}
}
}