noodles_vcf/variant/record_buf/info/field/
value.rs

1//! Variant record info field value.
2
3mod array;
4
5use std::{borrow::Cow, str};
6
7pub use self::array::Array;
8
9/// A variant record info field value.
10#[derive(Clone, Debug, PartialEq)]
11pub enum Value {
12    /// A 32-bit integer.
13    Integer(i32),
14    /// A single-precision floating-point.
15    Float(f32),
16    /// A boolean.
17    Flag,
18    /// A character.
19    Character(char),
20    /// A string.
21    String(String),
22    /// An array.
23    Array(Array),
24}
25
26impl From<i32> for Value {
27    fn from(n: i32) -> Self {
28        Self::Integer(n)
29    }
30}
31
32impl From<f32> for Value {
33    fn from(n: f32) -> Self {
34        Self::Float(n)
35    }
36}
37
38impl From<char> for Value {
39    fn from(c: char) -> Self {
40        Self::Character(c)
41    }
42}
43
44impl From<&str> for Value {
45    fn from(s: &str) -> Self {
46        Self::String(s.into())
47    }
48}
49
50impl From<String> for Value {
51    fn from(s: String) -> Self {
52        Self::String(s)
53    }
54}
55
56impl From<Vec<Option<i32>>> for Value {
57    fn from(values: Vec<Option<i32>>) -> Self {
58        Self::Array(Array::Integer(values))
59    }
60}
61
62impl From<Vec<Option<f32>>> for Value {
63    fn from(values: Vec<Option<f32>>) -> Self {
64        Self::Array(Array::Float(values))
65    }
66}
67
68impl From<Vec<Option<char>>> for Value {
69    fn from(values: Vec<Option<char>>) -> Self {
70        Self::Array(Array::Character(values))
71    }
72}
73
74impl From<Vec<Option<String>>> for Value {
75    fn from(values: Vec<Option<String>>) -> Self {
76        Self::Array(Array::String(values))
77    }
78}
79
80impl<'a> From<&'a Value> for crate::variant::record::info::field::Value<'a> {
81    fn from(value_buf: &'a Value) -> Self {
82        match value_buf {
83            Value::Integer(n) => Self::Integer(*n),
84            Value::Float(n) => Self::Float(*n),
85            Value::Flag => Self::Flag,
86            Value::Character(c) => Self::Character(*c),
87            Value::String(s) => Self::String(Cow::from(s.as_str())),
88            Value::Array(array) => Self::Array(array.into()),
89        }
90    }
91}