noodles_vcf/variant/record/samples/series/
value.rs

1//! Variant record samples value.
2
3pub mod array;
4pub mod genotype;
5
6use std::{borrow::Cow, io};
7
8pub use self::{array::Array, genotype::Genotype};
9
10/// A variant record samples value.
11#[derive(Debug)]
12pub enum Value<'a> {
13    /// A 32-bit integer.
14    Integer(i32),
15    /// A single-precision floating-point.
16    Float(f32),
17    /// A character.
18    Character(char),
19    /// A string.
20    String(Cow<'a, str>),
21    /// A genotype.
22    Genotype(Box<dyn Genotype + 'a>),
23    /// An array.
24    Array(Array<'a>),
25}
26
27impl<'a> TryFrom<Value<'a>> for crate::variant::record_buf::samples::sample::Value {
28    type Error = io::Error;
29
30    fn try_from(value: Value<'a>) -> Result<Self, Self::Error> {
31        match value {
32            Value::Integer(n) => Ok(Self::Integer(n)),
33            Value::Float(n) => Ok(Self::Float(n)),
34            Value::Character(c) => Ok(Self::Character(c)),
35            Value::String(s) => Ok(Self::String(s.into())),
36            Value::Genotype(genotype) => genotype.as_ref().try_into().map(Self::Genotype),
37            Value::Array(array) => array.try_into().map(Self::Array),
38        }
39    }
40}