noodles_vcf/variant/record_buf/samples/sample/
value.rs1mod array;
4pub mod genotype;
5
6use std::{borrow::Cow, str};
7
8pub use self::{array::Array, genotype::Genotype};
9
10#[derive(Clone, Debug, PartialEq)]
12pub enum Value {
13 Integer(i32),
15 Float(f32),
17 Character(char),
19 String(String),
21 Genotype(Genotype),
23 Array(Array),
25}
26
27impl From<i32> for Value {
28 fn from(n: i32) -> Self {
29 Self::Integer(n)
30 }
31}
32
33impl From<f32> for Value {
34 fn from(n: f32) -> Self {
35 Self::Float(n)
36 }
37}
38
39impl From<char> for Value {
40 fn from(c: char) -> Self {
41 Self::Character(c)
42 }
43}
44
45impl From<&str> for Value {
46 fn from(s: &str) -> Self {
47 Self::String(s.into())
48 }
49}
50
51impl From<String> for Value {
52 fn from(s: String) -> Self {
53 Self::String(s)
54 }
55}
56
57impl From<Genotype> for Value {
58 fn from(genotype: Genotype) -> Self {
59 Self::Genotype(genotype)
60 }
61}
62
63impl From<Vec<Option<i32>>> for Value {
64 fn from(values: Vec<Option<i32>>) -> Self {
65 Self::Array(Array::Integer(values))
66 }
67}
68
69impl From<Vec<Option<f32>>> for Value {
70 fn from(values: Vec<Option<f32>>) -> Self {
71 Self::Array(Array::Float(values))
72 }
73}
74
75impl From<Vec<Option<char>>> for Value {
76 fn from(values: Vec<Option<char>>) -> Self {
77 Self::Array(Array::Character(values))
78 }
79}
80
81impl From<Vec<Option<String>>> for Value {
82 fn from(values: Vec<Option<String>>) -> Self {
83 Self::Array(Array::String(values))
84 }
85}
86
87impl<'a> From<&'a Value> for crate::variant::record::samples::series::Value<'a> {
88 fn from(value_buf: &'a Value) -> Self {
89 match value_buf {
90 Value::Integer(n) => Self::Integer(*n),
91 Value::Float(n) => Self::Float(*n),
92 Value::Character(c) => Self::Character(*c),
93 Value::String(s) => Self::String(Cow::from(s)),
94 Value::Genotype(genotype) => Self::Genotype(Box::new(genotype)),
95 Value::Array(array) => Self::Array(array.into()),
96 }
97 }
98}