Skip to content

Commit b1dcea9

Browse files
committed
DeriveFrom for SingleArray
1 parent 8303482 commit b1dcea9

File tree

2 files changed

+11
-56
lines changed

2 files changed

+11
-56
lines changed

svd-rs/src/derive_from.rs

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Implementations of DeriveFrom, setting non-explicit fields.
22
use crate::{
3-
Cluster, ClusterInfo, EnumeratedValues, Field, FieldInfo, Peripheral, PeripheralInfo, Register,
4-
RegisterInfo, RegisterProperties,
3+
ClusterInfo, EnumeratedValues, FieldInfo, PeripheralInfo, RegisterInfo, RegisterProperties,
4+
SingleArray,
55
};
66

77
/// Fill empty fields of structure with values of other structure
@@ -107,69 +107,23 @@ impl DeriveFrom for FieldInfo {
107107
}
108108
}
109109

110-
impl DeriveFrom for Peripheral {
110+
impl<T> DeriveFrom for SingleArray<T>
111+
where
112+
T: DeriveFrom,
113+
{
111114
fn derive_from(&self, other: &Self) -> Self {
112115
match (self, other) {
113-
(Self::Single(info), Self::Single(other_info)) => info.derive_from(other_info).single(),
114-
(Self::Single(info), Self::Array(other_info, other_dim)) => {
115-
let mut dim = other_dim.clone();
116-
dim.dim_name = None;
117-
info.derive_from(other_info).array(dim)
118-
}
119-
(Self::Array(info, dim), Self::Single(other_info))
120-
| (Self::Array(info, dim), Self::Array(other_info, _)) => {
121-
info.derive_from(other_info).array(dim.clone())
122-
}
123-
}
124-
}
125-
}
126-
127-
impl DeriveFrom for Cluster {
128-
fn derive_from(&self, other: &Self) -> Self {
129-
match (self, other) {
130-
(Self::Single(info), Self::Single(other_info)) => info.derive_from(other_info).single(),
131-
(Self::Single(info), Self::Array(other_info, other_dim)) => {
132-
let mut dim = other_dim.clone();
133-
dim.dim_name = None;
134-
info.derive_from(other_info).array(dim)
135-
}
136-
(Self::Array(info, dim), Self::Single(other_info))
137-
| (Self::Array(info, dim), Self::Array(other_info, _)) => {
138-
info.derive_from(other_info).array(dim.clone())
116+
(Self::Single(info), Self::Single(other_info)) => {
117+
Self::Single(info.derive_from(other_info))
139118
}
140-
}
141-
}
142-
}
143-
144-
impl DeriveFrom for Register {
145-
fn derive_from(&self, other: &Self) -> Self {
146-
match (self, other) {
147-
(Self::Single(info), Self::Single(other_info)) => info.derive_from(other_info).single(),
148-
(Self::Single(info), Self::Array(other_info, other_dim)) => {
149-
let mut dim = other_dim.clone();
150-
dim.dim_name = None;
151-
info.derive_from(other_info).array(dim)
152-
}
153-
(Self::Array(info, dim), Self::Single(other_info))
154-
| (Self::Array(info, dim), Self::Array(other_info, _)) => {
155-
info.derive_from(other_info).array(dim.clone())
156-
}
157-
}
158-
}
159-
}
160-
161-
impl DeriveFrom for Field {
162-
fn derive_from(&self, other: &Self) -> Self {
163-
match (self, other) {
164-
(Self::Single(info), Self::Single(other_info)) => info.derive_from(other_info).single(),
165119
(Self::Single(info), Self::Array(other_info, other_dim)) => {
166120
let mut dim = other_dim.clone();
167121
dim.dim_name = None;
168-
info.derive_from(other_info).array(dim)
122+
Self::Array(info.derive_from(other_info), dim)
169123
}
170124
(Self::Array(info, dim), Self::Single(other_info))
171125
| (Self::Array(info, dim), Self::Array(other_info, _)) => {
172-
info.derive_from(other_info).array(dim.clone())
126+
Self::Array(info.derive_from(other_info), dim.clone())
173127
}
174128
}
175129
}

svd-rs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! This module defines components of an SVD along with parse and encode implementations
44
55
mod array;
6+
pub use array::SingleArray;
67

78
/// Endian objects
89
pub mod endian;

0 commit comments

Comments
 (0)