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
use serde_cbor::Value;
use std::collections::btree_map::{IntoIter, Iter};
use std::collections::BTreeMap;
pub type SignalId = u16;
#[derive(Debug, Clone)]
pub struct Signal(BTreeMap<SignalId, Value>);
impl Signal {
pub fn new(signals: impl Into<BTreeMap<SignalId, Value>>) -> Self {
Self(signals.into())
}
pub fn none() -> Self {
Self(BTreeMap::new())
}
pub fn get(&self, tag: SignalId) -> Option<&Value> {
self.0.get(&tag)
}
pub fn iter(&self) -> Iter<SignalId, Value> {
self.0.iter()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
impl From<Vec<(SignalId, Value)>> for Signal {
fn from(vec: Vec<(SignalId, Value)>) -> Self {
Self(vec.into_iter().collect())
}
}
impl IntoIterator for Signal {
type Item = (SignalId, Value);
type IntoIter = IntoIter<SignalId, Value>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}