dot_ix_model/common/
node_emojis.rs

1use std::ops::{Deref, DerefMut};
2
3use indexmap::IndexMap;
4use serde::{Deserialize, Serialize};
5
6use crate::common::NodeId;
7
8/// Each node's emoji. `IndexMap<NodeId, String>` newtype.
9#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
10pub struct NodeEmojis(IndexMap<NodeId, String>);
11
12impl NodeEmojis {
13    /// Returns a new `NodeEmojis` map.
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    /// Returns a new `NodeEmojis` map with the given preallocated
19    /// capacity.
20    pub fn with_capacity(capacity: usize) -> Self {
21        Self(IndexMap::with_capacity(capacity))
22    }
23
24    /// Returns the underlying map.
25    pub fn into_inner(self) -> IndexMap<NodeId, String> {
26        self.0
27    }
28}
29
30impl Deref for NodeEmojis {
31    type Target = IndexMap<NodeId, String>;
32
33    fn deref(&self) -> &Self::Target {
34        &self.0
35    }
36}
37
38impl DerefMut for NodeEmojis {
39    fn deref_mut(&mut self) -> &mut Self::Target {
40        &mut self.0
41    }
42}
43
44impl From<IndexMap<NodeId, String>> for NodeEmojis {
45    fn from(inner: IndexMap<NodeId, String>) -> Self {
46        Self(inner)
47    }
48}
49
50impl FromIterator<(NodeId, String)> for NodeEmojis {
51    fn from_iter<I: IntoIterator<Item = (NodeId, String)>>(iter: I) -> Self {
52        Self(IndexMap::from_iter(iter))
53    }
54}