11//! Implementations of DeriveFrom, setting non-explicit fields.
22use crate :: {
3- ClusterInfo , EnumeratedValues , FieldInfo , MaybeArray , PeripheralInfo , RegisterInfo ,
3+ ClusterInfo , DimElement , EnumeratedValues , FieldInfo , MaybeArray , PeripheralInfo , RegisterInfo ,
44 RegisterProperties ,
55} ;
66
@@ -110,6 +110,27 @@ impl DeriveFrom for FieldInfo {
110110 }
111111}
112112
113+ impl DeriveFrom for DimElement {
114+ fn derive_from ( & self , other : & Self ) -> Self {
115+ let Self {
116+ dim, // mandatory
117+ dim_increment : _, // mandatory
118+ dim_index,
119+ dim_name,
120+ dim_array_index,
121+ } = other;
122+
123+ let mut derived = self . clone ( ) ;
124+ derived. dim_name = derived. dim_name . or_else ( || dim_name. clone ( ) ) ;
125+ if derived. dim == * dim {
126+ // Only derive dimIndex and dimArrayIndex if the dimensions are the same.
127+ derived. dim_index = derived. dim_index . or_else ( || dim_index. clone ( ) ) ;
128+ derived. dim_array_index = derived. dim_array_index . or_else ( || dim_array_index. clone ( ) ) ;
129+ }
130+ derived
131+ }
132+ }
133+
113134impl < T > DeriveFrom for MaybeArray < T >
114135where
115136 T : DeriveFrom + crate :: Name ,
@@ -128,9 +149,12 @@ where
128149 Self :: Single ( info. derive_from ( other_info) )
129150 }
130151 }
131- ( Self :: Array ( info, dim) , Self :: Single ( other_info) | Self :: Array ( other_info , _ ) ) => {
152+ ( Self :: Array ( info, dim) , Self :: Single ( other_info) ) => {
132153 Self :: Array ( info. derive_from ( other_info) , dim. clone ( ) )
133154 }
155+ ( Self :: Array ( info, dim) , Self :: Array ( other_info, other_dim) ) => {
156+ Self :: Array ( info. derive_from ( other_info) , dim. derive_from ( other_dim) )
157+ }
134158 }
135159 }
136160}
0 commit comments