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
52
53
54
55
56
57
58
59
60
61
//! VCF record IDs.

use indexmap::IndexSet;

/// VCF record IDs (`ID`).
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Ids(IndexSet<String>);

impl AsRef<IndexSet<String>> for Ids {
    fn as_ref(&self) -> &IndexSet<String> {
        &self.0
    }
}

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

impl Extend<String> for Ids {
    fn extend<T: IntoIterator<Item = String>>(&mut self, iter: T) {
        self.0.extend(iter);
    }
}

impl FromIterator<String> for Ids {
    fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
        let mut ids = Self::default();
        ids.extend(iter);
        ids
    }
}

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

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

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

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

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

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