noodles_vcf/variant/record/samples/series/value/
array.rsmod values;
use std::{borrow::Cow, 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, Cow<'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::samples::sample::value::Array {
type Error = io::Error;
fn try_from(array: Array<'a>) -> Result<Self, Self::Error> {
match array {
Array::Integer(values) => values.iter().collect::<io::Result<_>>().map(Self::Integer),
Array::Float(values) => values.iter().collect::<io::Result<_>>().map(Self::Float),
Array::Character(values) => values
.iter()
.collect::<io::Result<_>>()
.map(Self::Character),
Array::String(values) => values
.iter()
.map(|result| result.map(|value| value.map(String::from)))
.collect::<io::Result<_>>()
.map(Self::String),
}
}
}