Skip to content

Commit 561aa27

Browse files
bors[bot]burrbull
andauthored
Merge #143
143: add missed DeriveFrom implementation r=therealprof a=burrbull r? @therealprof Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 192a14e + 229c128 commit 561aa27

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.10.1] - 2021-04-17
11+
12+
- Added `DeriveFrom` implementation for `FieldInfo`
13+
1014
## [v0.10.0] - 2021-04-04
1115

1216
- Added `strict` feature that hides part of checks
@@ -129,7 +133,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
129133
- Initial SVD parser
130134
- A `parse` utility function to parse the contents of a SVD file (XML)
131135

132-
[Unreleased]: https://github.com/rust-embedded/svd/compare/v0.10.0...HEAD
136+
[Unreleased]: https://github.com/rust-embedded/svd/compare/v0.10.1...HEAD
137+
[v0.10.1]: https://github.com/rust-embedded/svd/compare/v0.10.0...v0.10.1
133138
[v0.10.0]: https://github.com/rust-embedded/svd/compare/v0.9.0...v0.10.0
134139
[v0.9.0]: https://github.com/rust-embedded/svd/compare/v0.8.1...v0.9.0
135140
[v0.8.1]: https://github.com/rust-embedded/svd/compare/v0.8.0...v0.8.1

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
1010
name = "svd-parser"
1111
repository = "https://github.com/rust-embedded/svd"
1212
edition = "2018"
13-
version = "0.10.0"
13+
version = "0.10.1"
1414
readme = "README.md"
1515

1616
[features]

src/derive_from.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::{ClusterInfo, EnumeratedValues, Peripheral, RegisterInfo, RegisterProperties};
1+
use crate::{
2+
ClusterInfo, EnumeratedValues, FieldInfo, Peripheral, RegisterInfo, RegisterProperties,
3+
};
24

35
/// Fill empty fields of structure with values of other structure
46
pub trait DeriveFrom {
@@ -14,7 +16,7 @@ impl DeriveFrom for ClusterInfo {
1416
.derive_from(&other.default_register_properties);
1517
derived.header_struct_name = derived
1618
.header_struct_name
17-
.or(other.header_struct_name.clone());
19+
.or_else(|| other.header_struct_name.clone());
1820
if derived.children.is_empty() {
1921
derived.children = other.children.clone();
2022
}
@@ -25,7 +27,7 @@ impl DeriveFrom for ClusterInfo {
2527
impl DeriveFrom for EnumeratedValues {
2628
fn derive_from(&self, other: &Self) -> Self {
2729
let mut derived = self.clone();
28-
derived.usage = derived.usage.or(other.usage.clone());
30+
derived.usage = derived.usage.or_else(|| other.usage.clone());
2931
if derived.values.is_empty() {
3032
derived.values = other.values.clone();
3133
}
@@ -36,12 +38,12 @@ impl DeriveFrom for EnumeratedValues {
3638
impl DeriveFrom for Peripheral {
3739
fn derive_from(&self, other: &Self) -> Self {
3840
let mut derived = self.clone();
39-
derived.group_name = derived.group_name.or(other.group_name.clone());
40-
derived.description = derived.description.or(other.description.clone());
41+
derived.group_name = derived.group_name.or_else(|| other.group_name.clone());
42+
derived.description = derived.description.or_else(|| other.description.clone());
4143
derived.default_register_properties = derived
4244
.default_register_properties
4345
.derive_from(&other.default_register_properties);
44-
derived.registers = derived.registers.or(other.registers.clone());
46+
derived.registers = derived.registers.or_else(|| other.registers.clone());
4547
if derived.interrupt.is_empty() {
4648
derived.interrupt = other.interrupt.clone();
4749
}
@@ -52,12 +54,12 @@ impl DeriveFrom for Peripheral {
5254
impl DeriveFrom for RegisterInfo {
5355
fn derive_from(&self, other: &RegisterInfo) -> RegisterInfo {
5456
let mut derived = self.clone();
55-
derived.description = derived.description.or(other.description.clone());
57+
derived.description = derived.description.or_else(|| other.description.clone());
5658
derived.size = derived.size.or(other.size);
5759
derived.access = derived.access.or(other.access);
5860
derived.reset_value = derived.reset_value.or(other.reset_value);
5961
derived.reset_mask = derived.reset_mask.or(other.reset_mask);
60-
derived.fields = derived.fields.or(other.fields.clone());
62+
derived.fields = derived.fields.or_else(|| other.fields.clone());
6163
derived.write_constraint = derived.write_constraint.or(other.write_constraint);
6264
derived.modified_write_values = derived
6365
.modified_write_values
@@ -76,3 +78,19 @@ impl DeriveFrom for RegisterProperties {
7678
derived
7779
}
7880
}
81+
82+
impl DeriveFrom for FieldInfo {
83+
fn derive_from(&self, other: &Self) -> Self {
84+
let mut derived = self.clone();
85+
derived.description = derived.description.or_else(|| other.description.clone());
86+
derived.access = derived.access.or(other.access);
87+
if derived.enumerated_values.is_empty() {
88+
derived.enumerated_values = other.enumerated_values.clone();
89+
}
90+
derived.write_constraint = derived.write_constraint.or(other.write_constraint);
91+
derived.modified_write_values = derived
92+
.modified_write_values
93+
.or(other.modified_write_values);
94+
derived
95+
}
96+
}

0 commit comments

Comments
 (0)