noodles_vcf/variant/record_buf/
ids.rs

1//! VCF record IDs.
2
3use indexmap::IndexSet;
4
5/// VCF record IDs (`ID`).
6#[derive(Clone, Debug, Default, Eq, PartialEq)]
7pub struct Ids(IndexSet<String>);
8
9impl AsRef<IndexSet<String>> for Ids {
10    fn as_ref(&self) -> &IndexSet<String> {
11        &self.0
12    }
13}
14
15impl AsMut<IndexSet<String>> for Ids {
16    fn as_mut(&mut self) -> &mut IndexSet<String> {
17        &mut self.0
18    }
19}
20
21impl Extend<String> for Ids {
22    fn extend<T: IntoIterator<Item = String>>(&mut self, iter: T) {
23        self.0.extend(iter);
24    }
25}
26
27impl FromIterator<String> for Ids {
28    fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
29        let mut ids = Self::default();
30        ids.extend(iter);
31        ids
32    }
33}
34
35impl crate::variant::record::Ids for Ids {
36    fn is_empty(&self) -> bool {
37        self.0.is_empty()
38    }
39
40    fn len(&self) -> usize {
41        self.0.len()
42    }
43
44    fn iter(&self) -> Box<dyn Iterator<Item = &str> + '_> {
45        Box::new(self.0.iter().map(|id| id.as_ref()))
46    }
47}
48
49impl crate::variant::record::Ids for &Ids {
50    fn is_empty(&self) -> bool {
51        self.0.is_empty()
52    }
53
54    fn len(&self) -> usize {
55        self.0.len()
56    }
57
58    fn iter(&self) -> Box<dyn Iterator<Item = &str> + '_> {
59        Box::new(self.0.iter().map(|id| id.as_ref()))
60    }
61}