1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Variant record samples value.

pub mod array;
pub mod genotype;

use std::io;

pub use self::{array::Array, genotype::Genotype};

/// A variant record samples value.
#[derive(Debug)]
pub enum Value<'a> {
    /// A 32-bit integer.
    Integer(i32),
    /// A single-precision floating-point.
    Float(f32),
    /// A character.
    Character(char),
    /// A string.
    String(&'a str),
    /// A genotype.
    Genotype(Box<dyn Genotype + 'a>),
    /// An array.
    Array(Array<'a>),
}

impl<'a> TryFrom<Value<'a>> for crate::variant::record_buf::samples::sample::Value {
    type Error = io::Error;

    fn try_from(value: Value<'a>) -> Result<Self, Self::Error> {
        match value {
            Value::Integer(n) => Ok(Self::Integer(n)),
            Value::Float(n) => Ok(Self::Float(n)),
            Value::Character(c) => Ok(Self::Character(c)),
            Value::String(s) => Ok(Self::String(s.into())),
            Value::Genotype(genotype) => genotype.as_ref().try_into().map(Self::Genotype),
            Value::Array(array) => array.try_into().map(Self::Array),
        }
    }
}