|
1 | 1 | //! Implementations of DeriveFrom, setting non-explicit fields.
|
2 | 2 | use crate::{
|
3 |
| - Cluster, ClusterInfo, EnumeratedValues, Field, FieldInfo, Peripheral, PeripheralInfo, Register, |
4 |
| - RegisterInfo, RegisterProperties, |
| 3 | + ClusterInfo, EnumeratedValues, FieldInfo, PeripheralInfo, RegisterInfo, RegisterProperties, |
| 4 | + SingleArray, |
5 | 5 | };
|
6 | 6 |
|
7 | 7 | /// Fill empty fields of structure with values of other structure
|
@@ -107,69 +107,23 @@ impl DeriveFrom for FieldInfo {
|
107 | 107 | }
|
108 | 108 | }
|
109 | 109 |
|
110 |
| -impl DeriveFrom for Peripheral { |
| 110 | +impl<T> DeriveFrom for SingleArray<T> |
| 111 | +where |
| 112 | + T: DeriveFrom, |
| 113 | +{ |
111 | 114 | fn derive_from(&self, other: &Self) -> Self {
|
112 | 115 | 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)) |
139 | 118 | }
|
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(), |
165 | 119 | (Self::Single(info), Self::Array(other_info, other_dim)) => {
|
166 | 120 | let mut dim = other_dim.clone();
|
167 | 121 | dim.dim_name = None;
|
168 |
| - info.derive_from(other_info).array(dim) |
| 122 | + Self::Array(info.derive_from(other_info), dim) |
169 | 123 | }
|
170 | 124 | (Self::Array(info, dim), Self::Single(other_info))
|
171 | 125 | | (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()) |
173 | 127 | }
|
174 | 128 | }
|
175 | 129 | }
|
|
0 commit comments