Skip to content

Commit bf2544b

Browse files
bors[bot]burrbull
andauthored
Merge #213
213: dimIndex serialize r=therealprof a=burrbull Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
2 parents d0839b7 + f41b4d7 commit bf2544b

24 files changed

+100
-70
lines changed

svd-parser/src/dimelement.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::types::DimIndex;
21
use super::*;
32
use crate::svd::{DimArrayIndex, DimElement, EnumeratedValue};
43

@@ -44,3 +43,16 @@ impl Parse for DimArrayIndex {
4443
})
4544
}
4645
}
46+
47+
struct DimIndex;
48+
49+
impl Parse for DimIndex {
50+
type Object = Vec<String>;
51+
type Error = SVDErrorAt;
52+
type Config = Config;
53+
54+
fn parse(tree: &Node, _config: &Self::Config) -> Result<Vec<String>, Self::Error> {
55+
DimElement::parse_indexes(tree.get_text()?)
56+
.ok_or_else(|| SVDError::DimIndexParse.at(tree.id()))
57+
}
58+
}

svd-parser/src/elementext.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ impl<'a, 'input> ElementExt for Node<'a, 'input> {
3434
where
3535
K: AsRef<str>,
3636
{
37-
for c in self.children() {
38-
if c.has_tag_name(k.as_ref()) {
39-
return Some(c);
40-
}
41-
}
42-
None
37+
self.children().find(|&c| c.has_tag_name(k.as_ref()))
4338
}
4439
fn get_child_text_opt<K>(&self, k: K) -> Result<Option<String>, SVDErrorAt>
4540
where

svd-parser/src/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,11 @@ pub fn derive_enumerated_values(
571571
Ok(epath)
572572
}
573573
} else {
574-
return Err(anyhow!(
574+
Err(anyhow!(
575575
"enumeratedValues {} not found, parent field: {:?}",
576576
dpath,
577577
fpath,
578-
));
578+
))
579579
}
580580
}
581581

svd-parser/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub mod expand;
220220
#[cfg(feature = "expand")]
221221
pub use expand::{expand, expand_properties};
222222
/// SVD parse Errors.
223-
#[derive(Clone, Debug, PartialEq, thiserror::Error)]
223+
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
224224
pub enum SVDError {
225225
#[error("{0}")]
226226
Svd(#[from] svd::SvdError),

svd-parser/src/types.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use roxmltree::Node;
55

6-
use super::{Config, ElementExt, Parse, SVDError, SVDErrorAt};
6+
use super::{ElementExt, Parse, SVDError, SVDErrorAt};
77

88
impl Parse for u32 {
99
type Object = u32;
@@ -84,32 +84,3 @@ impl Parse for BoolParse {
8484
}
8585
}
8686
}
87-
88-
pub struct DimIndex;
89-
90-
impl Parse for DimIndex {
91-
type Object = Vec<String>;
92-
type Error = SVDErrorAt;
93-
type Config = Config;
94-
95-
fn parse(tree: &Node, _config: &Self::Config) -> Result<Vec<String>, Self::Error> {
96-
let text = tree.get_text()?;
97-
if text.contains('-') {
98-
let mut parts = text.splitn(2, '-');
99-
let start = parts
100-
.next()
101-
.ok_or_else(|| SVDError::DimIndexParse.at(tree.id()))?
102-
.parse::<u32>()
103-
.map_err(|e| SVDError::from(e).at(tree.id()))?;
104-
let end = parts
105-
.next()
106-
.ok_or_else(|| SVDError::DimIndexParse.at(tree.id()))?
107-
.parse::<u32>()
108-
.map_err(|e| SVDError::from(e).at(tree.id()))?;
109-
110-
Ok((start..=end).map(|i| i.to_string()).collect())
111-
} else {
112-
Ok(text.split(',').map(|s| s.to_string()).collect())
113-
}
114-
}
115-
}

svd-rs/CHANGELOG.md

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

88
## Unreleased
99

10+
- (De)serialize `dimIndex` (from)to string
11+
1012
## [v0.14.0] - 2022-07-19
1113

1214
- Bump MSRV to 1.56.0 (2021)

svd-rs/src/access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Defines access rights for fields on the device, though it may be specified at a
22
/// higher level than individual fields.
33
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
4-
#[derive(Clone, Copy, Debug, PartialEq)]
4+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
55
pub enum Access {
66
/// Read access is permitted. Write operations have an undefined effect.
77
#[cfg_attr(feature = "serde", serde(rename = "read-only"))]

svd-rs/src/addressblock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{BuildError, Protection, SvdError, ValidateLevel};
22

33
/// An uniquely mapped address block to a peripheral
44
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
5-
#[derive(Clone, Debug, PartialEq)]
5+
#[derive(Clone, Debug, PartialEq, Eq)]
66
#[non_exhaustive]
77
pub struct AddressBlock {
88
/// Specifies the start address of an address block relative to the peripheral [`baseAddress`](crate::Peripheral::base_address).
@@ -63,7 +63,7 @@ impl AddressBlockUsage {
6363
}
6464

6565
/// Builder for [`AddressBlock`]
66-
#[derive(Clone, Debug, Default, PartialEq)]
66+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
6767
pub struct AddressBlockBuilder {
6868
offset: Option<u32>,
6969
size: Option<u32>,

svd-rs/src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{DimElement, Name};
22
use core::ops::{Deref, DerefMut};
33

44
/// A single SVD instance or array of instances
5-
#[derive(Clone, Debug, PartialEq)]
5+
#[derive(Clone, Debug, PartialEq, Eq)]
66
pub enum MaybeArray<T> {
77
/// A single instance
88
Single(T),

svd-rs/src/bitrange.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub enum Error {
77
}
88

99
/// A bit range, describing the [least significant bit](Self::lsb) and [most significant bit](Self::msb)
10-
#[derive(Clone, Copy, Debug, PartialEq)]
10+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1111
pub struct BitRange {
1212
/// Value defining the position of the least significant bit of the field within the register
1313
pub offset: u32,
@@ -20,7 +20,7 @@ pub struct BitRange {
2020
}
2121

2222
/// The style of bit range that describes a [BitRange]
23-
#[derive(Clone, Copy, Debug, PartialEq)]
23+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2424
pub enum BitRangeType {
2525
/// A bit range in the format: `[<msb>:<lsb>]`
2626
BitRange,

0 commit comments

Comments
 (0)