mod values;
use std::{fmt, io};
pub use self::values::Values;
pub enum Array<'a> {
Integer(Box<dyn Values<'a, i32> + 'a>),
Float(Box<dyn Values<'a, f32> + 'a>),
Character(Box<dyn Values<'a, char> + 'a>),
String(Box<dyn Values<'a, &'a str> + 'a>),
}
impl<'a> fmt::Debug for Array<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Integer(values) => f.debug_list().entries(values.iter()).finish(),
Self::Float(values) => f.debug_list().entries(values.iter()).finish(),
Self::Character(values) => f.debug_list().entries(values.iter()).finish(),
Self::String(values) => f.debug_list().entries(values.iter()).finish(),
}
}
}
impl<'a> TryFrom<Array<'a>> for crate::variant::record_buf::info::field::value::Array {
type Error = io::Error;
fn try_from(array: Array<'a>) -> Result<Self, Self::Error> {
match array {
Array::Integer(values) => values.iter().collect::<Result<_, _>>().map(Self::Integer),
Array::Float(values) => values.iter().collect::<Result<_, _>>().map(Self::Float),
Array::Character(values) => {
values.iter().collect::<Result<_, _>>().map(Self::Character)
}
Array::String(values) => values
.iter()
.map(|result| result.map(|value| value.map(String::from)))
.collect::<Result<_, _>>()
.map(Self::String),
}
}
}