1use serde_cbor::Value;
2use std::collections::btree_map::{IntoIter, Iter};
3use std::collections::BTreeMap;
4
5pub type SignalId = u16;
6
7#[derive(Debug, Clone)]
8pub struct Signal(BTreeMap<SignalId, Value>);
9
10impl Signal {
11 pub fn new(signals: impl Into<BTreeMap<SignalId, Value>>) -> Self {
12 Self(signals.into())
13 }
14
15 pub fn none() -> Self {
16 Self(BTreeMap::new())
17 }
18
19 pub fn get(&self, tag: SignalId) -> Option<&Value> {
20 self.0.get(&tag)
21 }
22
23 pub fn iter(&self) -> Iter<SignalId, Value> {
24 self.0.iter()
25 }
26
27 pub fn is_empty(&self) -> bool {
28 self.0.is_empty()
29 }
30}
31
32impl From<Vec<(SignalId, Value)>> for Signal {
33 fn from(vec: Vec<(SignalId, Value)>) -> Self {
34 Self(vec.into_iter().collect())
35 }
36}
37
38impl IntoIterator for Signal {
39 type Item = (SignalId, Value);
40 type IntoIter = IntoIter<SignalId, Value>;
41
42 fn into_iter(self) -> Self::IntoIter {
43 self.0.into_iter()
44 }
45}