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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use super::{BuildError, Name, SvdError, ValidateLevel};
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Interrupt {
pub name: String,
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub description: Option<String>,
pub value: u32,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct InterruptBuilder {
name: Option<String>,
description: Option<String>,
value: Option<u32>,
}
impl From<Interrupt> for InterruptBuilder {
fn from(d: Interrupt) -> Self {
Self {
name: Some(d.name),
description: d.description,
value: Some(d.value),
}
}
}
impl InterruptBuilder {
pub fn name(mut self, value: String) -> Self {
self.name = Some(value);
self
}
pub fn description(mut self, value: Option<String>) -> Self {
self.description = value;
self
}
pub fn value(mut self, value: u32) -> Self {
self.value = Some(value);
self
}
pub fn build(self, lvl: ValidateLevel) -> Result<Interrupt, SvdError> {
let mut de = Interrupt {
name: self
.name
.ok_or_else(|| BuildError::Uninitialized("name".to_string()))?,
description: self.description,
value: self
.value
.ok_or_else(|| BuildError::Uninitialized("value".to_string()))?,
};
if !lvl.is_disabled() {
de.validate(lvl)?;
}
Ok(de)
}
}
impl Interrupt {
pub fn builder() -> InterruptBuilder {
InterruptBuilder::default()
}
pub fn modify_from(
&mut self,
builder: InterruptBuilder,
lvl: ValidateLevel,
) -> Result<(), SvdError> {
if let Some(name) = builder.name {
self.name = name;
}
if builder.description.is_some() {
self.description = builder.description;
}
if let Some(value) = builder.value {
self.value = value;
}
if !lvl.is_disabled() {
self.validate(lvl)
} else {
Ok(())
}
}
pub fn validate(&mut self, _lvl: ValidateLevel) -> Result<(), SvdError> {
Ok(())
}
}
impl Name for Interrupt {
fn name(&self) -> &str {
&self.name
}
}