|
1 | 1 | //! Implementations of DeriveFrom, setting non-explicit fields.
|
2 | 2 | use crate::{
|
3 |
| - ClusterInfo, EnumeratedValues, FieldInfo, Peripheral, RegisterInfo, RegisterProperties, |
| 3 | + Cluster, ClusterInfo, EnumeratedValues, Field, FieldInfo, Peripheral, Register, RegisterInfo, |
| 4 | + RegisterProperties, |
4 | 5 | };
|
5 | 6 |
|
6 | 7 | /// Fill empty fields of structure with values of other structure
|
@@ -53,7 +54,7 @@ impl DeriveFrom for Peripheral {
|
53 | 54 | }
|
54 | 55 |
|
55 | 56 | impl DeriveFrom for RegisterInfo {
|
56 |
| - fn derive_from(&self, other: &RegisterInfo) -> RegisterInfo { |
| 57 | + fn derive_from(&self, other: &Self) -> Self { |
57 | 58 | let mut derived = self.clone();
|
58 | 59 | derived.description = derived.description.or_else(|| other.description.clone());
|
59 | 60 | derived.properties = derived.properties.derive_from(&other.properties);
|
@@ -92,3 +93,54 @@ impl DeriveFrom for FieldInfo {
|
92 | 93 | derived
|
93 | 94 | }
|
94 | 95 | }
|
| 96 | + |
| 97 | +impl DeriveFrom for Cluster { |
| 98 | + fn derive_from(&self, other: &Self) -> Self { |
| 99 | + match (self, other) { |
| 100 | + (Self::Single(info), Self::Single(other_info)) => { |
| 101 | + Self::Single(info.derive_from(other_info)) |
| 102 | + } |
| 103 | + (Self::Single(info), Self::Array(other_info, other_dim)) => { |
| 104 | + Self::Array(info.derive_from(other_info), other_dim.clone()) |
| 105 | + } |
| 106 | + (Self::Array(info, dim), Self::Single(other_info)) |
| 107 | + | (Self::Array(info, dim), Self::Array(other_info, _)) => { |
| 108 | + Self::Array(info.derive_from(other_info), dim.clone()) |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +impl DeriveFrom for Register { |
| 115 | + fn derive_from(&self, other: &Self) -> Self { |
| 116 | + match (self, other) { |
| 117 | + (Self::Single(info), Self::Single(other_info)) => { |
| 118 | + Self::Single(info.derive_from(other_info)) |
| 119 | + } |
| 120 | + (Self::Single(info), Self::Array(other_info, other_dim)) => { |
| 121 | + Self::Array(info.derive_from(other_info), other_dim.clone()) |
| 122 | + } |
| 123 | + (Self::Array(info, dim), Self::Single(other_info)) |
| 124 | + | (Self::Array(info, dim), Self::Array(other_info, _)) => { |
| 125 | + Self::Array(info.derive_from(other_info), dim.clone()) |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +impl DeriveFrom for Field { |
| 132 | + fn derive_from(&self, other: &Self) -> Self { |
| 133 | + match (self, other) { |
| 134 | + (Self::Single(info), Self::Single(other_info)) => { |
| 135 | + Self::Single(info.derive_from(other_info)) |
| 136 | + } |
| 137 | + (Self::Single(info), Self::Array(other_info, other_dim)) => { |
| 138 | + Self::Array(info.derive_from(other_info), other_dim.clone()) |
| 139 | + } |
| 140 | + (Self::Array(info, dim), Self::Single(other_info)) |
| 141 | + | (Self::Array(info, dim), Self::Array(other_info, _)) => { |
| 142 | + Self::Array(info.derive_from(other_info), dim.clone()) |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | +} |
0 commit comments