1
1
//! Implementations of DeriveFrom, setting non-explicit fields.
2
2
use crate :: {
3
- ClusterInfo , EnumeratedValues , FieldInfo , MaybeArray , PeripheralInfo , RegisterInfo ,
3
+ ClusterInfo ,
4
+ DimElement ,
5
+ EnumeratedValues ,
6
+ FieldInfo ,
7
+ MaybeArray ,
8
+ PeripheralInfo ,
9
+ RegisterInfo ,
4
10
RegisterProperties ,
5
11
} ;
6
12
@@ -110,6 +116,24 @@ impl DeriveFrom for FieldInfo {
110
116
}
111
117
}
112
118
119
+ impl DeriveFrom for DimElement {
120
+ fn derive_from ( & self , other : & Self ) -> Self {
121
+ let Self {
122
+ dim : _, // mandatory
123
+ dim_increment : _, // mandatory
124
+ dim_index,
125
+ dim_name,
126
+ dim_array_index,
127
+ } = other;
128
+
129
+ let mut derived = self . clone ( ) ;
130
+ derived. dim_index = derived. dim_index . or_else ( || dim_index. clone ( ) ) ;
131
+ derived. dim_name = derived. dim_name . or_else ( || dim_name. clone ( ) ) ;
132
+ derived. dim_array_index = derived. dim_array_index . or_else ( || dim_array_index. clone ( ) ) ;
133
+ derived
134
+ }
135
+ }
136
+
113
137
impl < T > DeriveFrom for MaybeArray < T >
114
138
where
115
139
T : DeriveFrom + crate :: Name ,
@@ -128,9 +152,12 @@ where
128
152
Self :: Single ( info. derive_from ( other_info) )
129
153
}
130
154
}
131
- ( Self :: Array ( info, dim) , Self :: Single ( other_info) | Self :: Array ( other_info , _ ) ) => {
155
+ ( Self :: Array ( info, dim) , Self :: Single ( other_info) ) => {
132
156
Self :: Array ( info. derive_from ( other_info) , dim. clone ( ) )
133
157
}
158
+ ( Self :: Array ( info, dim) , Self :: Array ( other_info, other_dim) ) => {
159
+ Self :: Array ( info. derive_from ( other_info) , dim. derive_from ( other_dim) )
160
+ }
134
161
}
135
162
}
136
163
}
0 commit comments