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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::rc::Rc;
use crate::model::*;
#[non_exhaustive]
#[derive(Copy, Clone, Debug)]
pub enum Representation {
Hex,
}
#[non_exhaustive]
#[derive(Copy, Clone, Debug)]
pub enum ConstantValue {
U8(u8, Representation),
}
#[derive(Debug)]
pub(crate) struct Constant<T>
where
T: DocReference,
{
pub(crate) name: Name,
pub(crate) value: ConstantValue,
pub(crate) doc: Doc<T>,
}
impl Constant<Unvalidated> {
pub(crate) fn validate(&self, lib: &LibraryFields) -> BindResult<Constant<Validated>> {
Ok(Constant {
name: self.name.clone(),
value: self.value,
doc: self.doc.validate(&self.name, lib)?,
})
}
}
#[derive(Debug)]
pub struct ConstantSet<T>
where
T: DocReference,
{
pub(crate) name: Name,
pub(crate) settings: Rc<LibrarySettings>,
pub(crate) values: Vec<Constant<T>>,
pub(crate) doc: Doc<T>,
}
impl ConstantSet<Unvalidated> {
pub(crate) fn validate(
&self,
lib: &LibraryFields,
) -> BindResult<Handle<ConstantSet<Validated>>> {
let values: BindResult<Vec<Constant<Validated>>> =
self.values.iter().map(|x| x.validate(lib)).collect();
Ok(Handle::new(ConstantSet {
name: self.name.clone(),
settings: self.settings.clone(),
values: values?,
doc: self.doc.validate(&self.name, lib)?,
}))
}
}
pub type ConstantSetHandle = Handle<ConstantSet<Unvalidated>>;