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
41
42
43
44
45
46
47
48
49
50
51
use std::io;

/// A variant record alternate bases buffer.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct AlternateBases(Vec<String>);

impl AsRef<[String]> for AlternateBases {
    fn as_ref(&self) -> &[String] {
        &self.0
    }
}

impl AsMut<Vec<String>> for AlternateBases {
    fn as_mut(&mut self) -> &mut Vec<String> {
        &mut self.0
    }
}

impl From<Vec<String>> for AlternateBases {
    fn from(alleles: Vec<String>) -> Self {
        Self(alleles)
    }
}

impl crate::variant::record::AlternateBases for AlternateBases {
    fn is_empty(&self) -> bool {
        self.0.is_empty()
    }

    fn len(&self) -> usize {
        self.0.len()
    }

    fn iter(&self) -> Box<dyn Iterator<Item = io::Result<&str>> + '_> {
        Box::new(self.0.iter().map(|allele| allele.as_ref()).map(Ok))
    }
}

impl crate::variant::record::AlternateBases for &AlternateBases {
    fn is_empty(&self) -> bool {
        self.0.is_empty()
    }

    fn len(&self) -> usize {
        self.0.len()
    }

    fn iter(&self) -> Box<dyn Iterator<Item = io::Result<&str>> + '_> {
        Box::new(self.0.iter().map(|allele| allele.as_ref()).map(Ok))
    }
}