noodles_vcf/variant/record/samples/series/value/
array.rs1mod values;
4
5use std::{borrow::Cow, fmt, io};
6
7pub use self::values::Values;
8
9pub enum Array<'a> {
11 Integer(Box<dyn Values<'a, i32> + 'a>),
13 Float(Box<dyn Values<'a, f32> + 'a>),
15 Character(Box<dyn Values<'a, char> + 'a>),
17 String(Box<dyn Values<'a, Cow<'a, str>> + 'a>),
19}
20
21impl fmt::Debug for Array<'_> {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Self::Integer(values) => f.debug_list().entries(values.iter()).finish(),
25 Self::Float(values) => f.debug_list().entries(values.iter()).finish(),
26 Self::Character(values) => f.debug_list().entries(values.iter()).finish(),
27 Self::String(values) => f.debug_list().entries(values.iter()).finish(),
28 }
29 }
30}
31
32impl<'a> TryFrom<Array<'a>> for crate::variant::record_buf::samples::sample::value::Array {
33 type Error = io::Error;
34
35 fn try_from(array: Array<'a>) -> Result<Self, Self::Error> {
36 match array {
37 Array::Integer(values) => values.iter().collect::<io::Result<_>>().map(Self::Integer),
38 Array::Float(values) => values.iter().collect::<io::Result<_>>().map(Self::Float),
39 Array::Character(values) => values
40 .iter()
41 .collect::<io::Result<_>>()
42 .map(Self::Character),
43 Array::String(values) => values
44 .iter()
45 .map(|result| result.map(|value| value.map(String::from)))
46 .collect::<io::Result<_>>()
47 .map(Self::String),
48 }
49 }
50}