Skip to content

Commit 60faa4e

Browse files
committed
Apply rustfmt
1 parent 5654cb7 commit 60faa4e

28 files changed

+636
-466
lines changed

src/elementext.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
44
use xmltree::Element;
55

6-
use types::{Parse, BoolParse};
76
use failure::ResultExt;
7+
use types::{BoolParse, Parse};
88

99
use error::*;
1010

@@ -36,7 +36,9 @@ impl ElementExt for Element {
3636
String: PartialEq<K>,
3737
{
3838
if let Some(child) = self.get_child(k) {
39-
Ok(Some(child.get_text().map(|s| s.to_owned())?))
39+
Ok(Some(child
40+
.get_text()
41+
.map(|s| s.to_owned())?))
4042
} else {
4143
Ok(None)
4244
}
@@ -46,7 +48,9 @@ impl ElementExt for Element {
4648
String: PartialEq<K>,
4749
K: ::std::fmt::Display + Clone,
4850
{
49-
self.get_child_text_opt(k.clone())?.ok_or(SVDErrorKind::MissingTag(self.clone(), format!("{}", k)).into(),)
51+
self.get_child_text_opt(k.clone())?.ok_or(
52+
SVDErrorKind::MissingTag(self.clone(), format!("{}", k)).into(),
53+
)
5054
}
5155

5256
/// Get text contained by an XML Element
@@ -56,25 +60,29 @@ impl ElementExt for Element {
5660
// FIXME: Doesn't look good because SVDErrorKind doesn't format by itself. We already
5761
// capture the element and this information can be used for getting the name
5862
// This would fix ParseError
59-
None => {
60-
Err(SVDErrorKind::EmptyTag(self.clone(), self.name.clone())
61-
.into())
62-
}
63+
None => Err(SVDErrorKind::EmptyTag(
64+
self.clone(),
65+
self.name.clone(),
66+
).into()),
6367
}
6468
}
6569

6670
/// Get a named child element from an XML Element
6771
fn get_child_elem<'a>(&'a self, n: &str) -> Result<&'a Element, SVDError> {
6872
match self.get_child(n) {
6973
Some(s) => Ok(s),
70-
None => Err(SVDErrorKind::MissingTag(self.clone(), n.to_string()).into()),
74+
None => Err(
75+
SVDErrorKind::MissingTag(self.clone(), n.to_string()).into(),
76+
),
7177
}
7278
}
7379

7480
/// Get a u32 value from a named child element
7581
fn get_child_u32(&self, n: &str) -> Result<u32, SVDError> {
7682
let s = self.get_child_elem(n)?;
77-
u32::parse(&s).context(SVDErrorKind::ParseError(self.clone())).map_err(|e| e.into())
83+
u32::parse(&s)
84+
.context(SVDErrorKind::ParseError(self.clone()))
85+
.map_err(|e| e.into())
7886
}
7987

8088
/// Get a bool value from a named child element
@@ -86,7 +94,7 @@ impl ElementExt for Element {
8694
// Merges the children of two elements, maintaining the name and description of the first
8795
fn merge(&self, r: &Self) -> Self {
8896
let mut n = self.clone();
89-
for c in &r.children {
97+
for c in &r.children {
9098
n.children.push(c.clone());
9199
}
92100
n

src/error.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! SVD Errors.
22
//! This module defines error types and messages for SVD parsing and encoding
33
4-
use xmltree::{Element, ParseError};
54
use failure::{Backtrace, Context, Fail};
65
use std::fmt::{self, Display};
7-
6+
use xmltree::{Element, ParseError};
87

98
#[derive(Debug)]
109
pub struct SVDError {
@@ -39,11 +38,18 @@ pub enum SVDErrorKind {
3938
UnknownUsageVariant(Element),
4039
#[fail(display = "Expected a <{}>, found ...", _1)]
4140
NotExpectedTag(Element, String),
42-
#[fail(display = "Invalid RegisterCluster (expected register or cluster), found {}", _1)]
41+
#[fail(
42+
display = "Invalid RegisterCluster (expected register or cluster), found {}",
43+
_1
44+
)]
4345
InvalidRegisterCluster(Element, String),
4446
#[fail(display = "Invalid modifiedWriteValues variant, found {}", _1)]
4547
InvalidModifiedWriteValues(Element, String),
46-
#[fail(display = "The content of the element could not be parsed to a boolean value {}: {}", _1, _2)]
48+
#[fail(
49+
display = "The content of the element could not be parsed to a boolean value {}: {}",
50+
_1,
51+
_2
52+
)]
4753
InvalidBooleanValue(Element, String, ::std::str::ParseBoolError),
4854
#[fail(display = "encoding method not implemented for svd object {}", _0)]
4955
EncodeNotImplemented(String),
@@ -86,7 +92,9 @@ impl SVDError {
8692

8793
impl From<SVDErrorKind> for SVDError {
8894
fn from(kind: SVDErrorKind) -> SVDError {
89-
SVDError { inner: Context::new(kind) }
95+
SVDError {
96+
inner: Context::new(kind),
97+
}
9098
}
9199
}
92100

@@ -98,6 +106,8 @@ impl From<Context<SVDErrorKind>> for SVDError {
98106

99107
impl From<ParseError> for SVDError {
100108
fn from(e: ParseError) -> SVDError {
101-
SVDError { inner: e.context(SVDErrorKind::FileParseError) }
109+
SVDError {
110+
inner: e.context(SVDErrorKind::FileParseError),
111+
}
102112
}
103113
}

src/lib.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub mod svd;
4141
pub use svd::*;
4242
// Error defines SVD error types
4343
pub mod error;
44-
use error::{SVDError};
44+
use error::SVDError;
4545
// Parse defines parsing interfaces
4646
pub mod parse;
4747
use parse::Parse;
@@ -80,28 +80,41 @@ fn trim_utf8_bom(s: &str) -> &str {
8080

8181
/// Helper to create new base xml elements
8282
#[cfg(feature = "unproven")]
83-
pub (crate) fn new_element(name: &str, text: Option<String>) -> Element {
83+
pub(crate) fn new_element(name: &str, text: Option<String>) -> Element {
8484
Element {
8585
name: String::from(name),
8686
attributes: HashMap::new(),
8787
children: Vec::new(),
8888
text: text,
89-
}
89+
}
9090
}
9191

9292
/// Generic test helper function
9393
/// Takes an array of (item, xml) pairs where the item implements
9494
/// Parse and Encode and tests object encoding and decoding
9595
#[cfg(test)]
9696
#[cfg(feature = "unproven")]
97-
pub fn run_test<T: Parse<Error=SVDError, Object=T> + Encode<Error=SVDError> + ::std::fmt::Debug + PartialEq>(tests: &[(T, &str)]) {
97+
pub fn run_test<
98+
T: Parse<Error = SVDError, Object = T>
99+
+ Encode<Error = SVDError>
100+
+ ::std::fmt::Debug
101+
+ PartialEq,
102+
>(
103+
tests: &[(T, &str)],
104+
) {
98105
for t in tests {
99106
let tree1 = Element::parse(t.1.as_bytes()).unwrap();
100107
let elem = T::parse(&tree1).unwrap();
101-
assert_eq!(elem, t.0, "Error parsing xml` (mismatch between parsed and expected)");
108+
assert_eq!(
109+
elem, t.0,
110+
"Error parsing xml` (mismatch between parsed and expected)"
111+
);
102112
let tree2 = elem.encode().unwrap();
103-
assert_eq!(tree1, tree2, "Error encoding xml (mismatch between encoded and original)");
104-
};
113+
assert_eq!(
114+
tree1, tree2,
115+
"Error encoding xml (mismatch between encoded and original)"
116+
);
117+
}
105118
}
106119

107120
#[cfg(test)]
@@ -117,4 +130,3 @@ mod tests {
117130
assert_eq!("xyz", trim_utf8_bom("xyz"));
118131
}
119132
}
120-

src/parse.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ pub trait Parse {
1515
fn parse(&Element) -> Result<Self::Object, Self::Error>;
1616
}
1717

18-
1918
/// Parses an optional child element with the provided name and Parse function
2019
/// Returns an none if the child doesn't exist, Ok(Some(e)) if parsing succeeds,
2120
/// and Err() if parsing fails.
22-
pub fn optional<'a, T>(n: &str, e: &'a Element) -> Result<Option<T::Object>, SVDError>
23-
where T: Parse<Error = SVDError>
21+
pub fn optional<'a, T>(
22+
n: &str,
23+
e: &'a Element,
24+
) -> Result<Option<T::Object>, SVDError>
25+
where
26+
T: Parse<Error = SVDError>,
2427
{
2528
let child = match e.get_child(n) {
2629
Some(c) => c,
@@ -32,4 +35,3 @@ where T: Parse<Error = SVDError>
3235
Err(e) => Err(e),
3336
}
3437
}
35-

src/svd/access.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
21
use xmltree::Element;
32

43
use elementext::ElementExt;
5-
use types::Parse;
64
#[cfg(feature = "unproven")]
75
use encode::Encode;
6+
use error::*;
87
#[cfg(feature = "unproven")]
98
use new_element;
10-
use error::*;
11-
9+
use types::Parse;
1210

1311
#[derive(Clone, Copy, Debug, PartialEq)]
1412
pub enum Access {
@@ -63,26 +61,14 @@ mod tests {
6361
#[test]
6462
fn decode_encode() {
6563
let tests = vec![
66-
(
67-
Access::ReadOnly,
68-
"<access>read-only</access>"
69-
),
70-
(
71-
Access::ReadWrite,
72-
"<access>read-write</access>"
73-
),
64+
(Access::ReadOnly, "<access>read-only</access>"),
65+
(Access::ReadWrite, "<access>read-write</access>"),
7466
(
7567
Access::ReadWriteOnce,
76-
"<access>read-writeOnce</access>"
77-
),
78-
(
79-
Access::WriteOnly,
80-
"<access>write-only</access>"
81-
),
82-
(
83-
Access::WriteOnce,
84-
"<access>writeOnce</access>"
68+
"<access>read-writeOnce</access>",
8569
),
70+
(Access::WriteOnly, "<access>write-only</access>"),
71+
(Access::WriteOnce, "<access>writeOnce</access>"),
8672
];
8773

8874
run_test::<Access>(&tests[..]);

src/svd/addressblock.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
21
#[cfg(feature = "unproven")]
32
use std::collections::HashMap;
43

5-
use xmltree::Element;
64
use elementext::ElementExt;
5+
use xmltree::Element;
76

87
use types::Parse;
98

109
#[cfg(feature = "unproven")]
1110
use encode::Encode;
11+
use error::SVDError;
1212
#[cfg(feature = "unproven")]
1313
use new_element;
14-
use error::SVDError;
1514

1615
#[derive(Clone, Debug, PartialEq)]
1716
pub struct AddressBlock {
@@ -57,23 +56,20 @@ mod tests {
5756
use super::*;
5857
use run_test;
5958

60-
6159
#[test]
6260
fn decode_encode() {
63-
let tests = vec![
64-
(
65-
AddressBlock {
66-
offset: 0,
67-
size: 0x00000800,
68-
usage: String::from("registers"),
69-
},
70-
"<addressBlock>
61+
let tests = vec![(
62+
AddressBlock {
63+
offset: 0,
64+
size: 0x00000800,
65+
usage: String::from("registers"),
66+
},
67+
"<addressBlock>
7168
<offset>0</offset>
7269
<size>0x00000800</size>
7370
<usage>registers</usage>
74-
</addressBlock>"
75-
),
76-
];
71+
</addressBlock>",
72+
)];
7773

7874
run_test::<AddressBlock>(&tests[..]);
7975
}

0 commit comments

Comments
 (0)