1use super::{BuildError, Description, Name, SvdError, ValidateLevel};
2
3#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
5#[derive(Clone, Debug, PartialEq, Eq)]
6#[non_exhaustive]
7pub struct Interrupt {
8 pub name: String,
10
11 #[cfg_attr(
13 feature = "serde",
14 serde(default, skip_serializing_if = "Option::is_none")
15 )]
16 pub description: Option<String>,
17
18 pub value: u32,
20}
21
22#[derive(Clone, Debug, Default, PartialEq, Eq)]
24pub struct InterruptBuilder {
25 name: Option<String>,
26 description: Option<String>,
27 value: Option<u32>,
28}
29
30impl From<Interrupt> for InterruptBuilder {
31 fn from(d: Interrupt) -> Self {
32 Self {
33 name: Some(d.name),
34 description: d.description,
35 value: Some(d.value),
36 }
37 }
38}
39
40impl InterruptBuilder {
41 pub fn name(mut self, value: String) -> Self {
43 self.name = Some(value);
44 self
45 }
46 pub fn description(mut self, value: Option<String>) -> Self {
48 self.description = value;
49 self
50 }
51 pub fn value(mut self, value: u32) -> Self {
53 self.value = Some(value);
54 self
55 }
56 pub fn build(self, lvl: ValidateLevel) -> Result<Interrupt, SvdError> {
58 let de = Interrupt {
59 name: self
60 .name
61 .ok_or_else(|| BuildError::Uninitialized("name".to_string()))?,
62 description: self.description,
63 value: self
64 .value
65 .ok_or_else(|| BuildError::Uninitialized("value".to_string()))?,
66 };
67 de.validate(lvl)?;
68 Ok(de)
69 }
70}
71
72impl Interrupt {
73 pub fn builder() -> InterruptBuilder {
75 InterruptBuilder::default()
76 }
77 pub fn modify_from(
79 &mut self,
80 builder: InterruptBuilder,
81 lvl: ValidateLevel,
82 ) -> Result<(), SvdError> {
83 if let Some(name) = builder.name {
84 self.name = name;
85 }
86 if builder.description.is_some() {
87 self.description = builder.description;
88 }
89 if let Some(value) = builder.value {
90 self.value = value;
91 }
92 self.validate(lvl)
93 }
94 pub fn validate(&self, _lvl: ValidateLevel) -> Result<(), SvdError> {
100 Ok(())
101 }
102}
103
104impl Name for Interrupt {
105 fn name(&self) -> &str {
106 &self.name
107 }
108}
109
110impl Description for Interrupt {
111 fn description(&self) -> Option<&str> {
112 self.description.as_deref()
113 }
114}