noodles_gff/record_buf/
attributes.rs

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
//! GFF record attributes.

pub mod field;

use indexmap::IndexMap;

use self::field::{Tag, Value};

/// GFF record attributes.
///
/// Attributes are extra data attached to a GFF record. They are represented as a typed map, where
/// each key ([`Tag`]) is associated with a typed [`Value`].
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Attributes(IndexMap<Tag, Value>);

impl Attributes {
    /// Returns whether there are any entries.
    pub fn is_empty(&self) -> bool {
        self.0.is_empty()
    }

    /// Returns the number of entries.
    pub fn len(&self) -> usize {
        self.0.len()
    }

    /// Returns the value at the given tag.
    pub fn get(&self, tag: &str) -> Option<&Value> {
        self.0.get(tag)
    }
}

impl AsRef<IndexMap<Tag, Value>> for Attributes {
    fn as_ref(&self) -> &IndexMap<Tag, Value> {
        &self.0
    }
}

impl AsMut<IndexMap<Tag, Value>> for Attributes {
    fn as_mut(&mut self) -> &mut IndexMap<Tag, Value> {
        &mut self.0
    }
}

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

impl FromIterator<(Tag, Value)> for Attributes {
    fn from_iter<T: IntoIterator<Item = (Tag, Value)>>(iter: T) -> Self {
        let mut attributes = Self::default();
        attributes.extend(iter);
        attributes
    }
}