noodles_sam/alignment/record/data/field/value/
array.rs1mod subtype;
4mod values;
5
6use std::{fmt, io};
7
8pub use self::{subtype::Subtype, values::Values};
9
10pub enum Array<'a> {
12 Int8(Box<dyn Values<'a, i8> + 'a>),
14 UInt8(Box<dyn Values<'a, u8> + 'a>),
16 Int16(Box<dyn Values<'a, i16> + 'a>),
18 UInt16(Box<dyn Values<'a, u16> + 'a>),
20 Int32(Box<dyn Values<'a, i32> + 'a>),
22 UInt32(Box<dyn Values<'a, u32> + 'a>),
24 Float(Box<dyn Values<'a, f32> + 'a>),
26}
27
28impl Array<'_> {
29 pub fn subtype(&self) -> Subtype {
31 match self {
32 Array::Int8(_) => Subtype::Int8,
33 Array::UInt8(_) => Subtype::UInt8,
34 Array::Int16(_) => Subtype::Int16,
35 Array::UInt16(_) => Subtype::UInt16,
36 Array::Int32(_) => Subtype::Int32,
37 Array::UInt32(_) => Subtype::UInt32,
38 Array::Float(_) => Subtype::Float,
39 }
40 }
41}
42
43impl fmt::Debug for Array<'_> {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 match self {
46 Self::Int8(values) => f.debug_list().entries(values.iter()).finish(),
47 Self::UInt8(values) => f.debug_list().entries(values.iter()).finish(),
48 Self::Int16(values) => f.debug_list().entries(values.iter()).finish(),
49 Self::UInt16(values) => f.debug_list().entries(values.iter()).finish(),
50 Self::Int32(values) => f.debug_list().entries(values.iter()).finish(),
51 Self::UInt32(values) => f.debug_list().entries(values.iter()).finish(),
52 Self::Float(values) => f.debug_list().entries(values.iter()).finish(),
53 }
54 }
55}
56
57impl<'a> TryFrom<Array<'a>> for crate::alignment::record_buf::data::field::value::Array {
58 type Error = io::Error;
59
60 fn try_from(array: Array<'a>) -> Result<Self, Self::Error> {
61 match array {
62 Array::Int8(values) => values.iter().collect::<Result<_, _>>().map(Self::Int8),
63 Array::UInt8(values) => values.iter().collect::<Result<_, _>>().map(Self::UInt8),
64 Array::Int16(values) => values.iter().collect::<Result<_, _>>().map(Self::Int16),
65 Array::UInt16(values) => values.iter().collect::<Result<_, _>>().map(Self::UInt16),
66 Array::Int32(values) => values.iter().collect::<Result<_, _>>().map(Self::Int32),
67 Array::UInt32(values) => values.iter().collect::<Result<_, _>>().map(Self::UInt32),
68 Array::Float(values) => values.iter().collect::<Result<_, _>>().map(Self::Float),
69 }
70 }
71}