Skip to content

Commit 1eb1408

Browse files
committed
Run cargo-fmt
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
1 parent 6c51d3b commit 1eb1408

File tree

17 files changed

+163
-144
lines changed

17 files changed

+163
-144
lines changed

src/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ impl Config {
161161
match value {
162162
Some(value) => {
163163
// Deserialize the received value into the requested type
164-
T::deserialize(value)
165-
.map_err(|e| e.extend_with_key(key))
164+
T::deserialize(value).map_err(|e| e.extend_with_key(key))
166165
}
167166

168167
None => Err(ConfigError::NotFound(key.into())),

src/de.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use error::*;
33
use serde::de;
44
use std::collections::{HashMap, VecDeque};
55
use std::iter::Enumerate;
6-
use value::{Value, ValueKind, Table};
6+
use value::{Table, Value, ValueKind};
77

88
impl<'de> de::Deserializer<'de> for Value {
99
type Error = ConfigError;
@@ -125,7 +125,11 @@ impl<'de> de::Deserializer<'de> for Value {
125125
where
126126
V: de::Visitor<'de>,
127127
{
128-
visitor.visit_enum(EnumAccess{ value: self, name, variants })
128+
visitor.visit_enum(EnumAccess {
129+
value: self,
130+
name,
131+
variants,
132+
})
129133
}
130134

131135
forward_to_deserialize_any! {
@@ -178,11 +182,10 @@ impl<'de> de::SeqAccess<'de> for SeqAccess {
178182
T: de::DeserializeSeed<'de>,
179183
{
180184
match self.elements.next() {
181-
Some((idx, value)) => {
182-
seed.deserialize(value)
183-
.map(Some)
184-
.map_err(|e| e.prepend_index(idx))
185-
}
185+
Some((idx, value)) => seed
186+
.deserialize(value)
187+
.map(Some)
188+
.map_err(|e| e.prepend_index(idx)),
186189
None => Ok(None),
187190
}
188191
}
@@ -229,8 +232,7 @@ impl<'de> de::MapAccess<'de> for MapAccess {
229232
V: de::DeserializeSeed<'de>,
230233
{
231234
let (key, value) = self.elements.pop_front().unwrap();
232-
de::DeserializeSeed::deserialize(seed, value)
233-
.map_err(|e| e.prepend_key(key))
235+
de::DeserializeSeed::deserialize(seed, value).map_err(|e| e.prepend_key(key))
234236
}
235237
}
236238

@@ -315,21 +317,21 @@ impl<'de> de::VariantAccess<'de> for EnumAccess {
315317
V: de::Visitor<'de>,
316318
{
317319
match self.value.kind {
318-
ValueKind::Table(t) => de::Deserializer::deserialize_seq(t.into_iter().next().unwrap().1, visitor),
320+
ValueKind::Table(t) => {
321+
de::Deserializer::deserialize_seq(t.into_iter().next().unwrap().1, visitor)
322+
}
319323
_ => unreachable!(),
320324
}
321325
}
322326

323-
fn struct_variant<V>(
324-
self,
325-
_fields: &'static [&'static str],
326-
visitor: V,
327-
) -> Result<V::Value>
327+
fn struct_variant<V>(self, _fields: &'static [&'static str], visitor: V) -> Result<V::Value>
328328
where
329329
V: de::Visitor<'de>,
330330
{
331331
match self.value.kind {
332-
ValueKind::Table(t) => de::Deserializer::deserialize_map(t.into_iter().next().unwrap().1, visitor),
332+
ValueKind::Table(t) => {
333+
de::Deserializer::deserialize_map(t.into_iter().next().unwrap().1, visitor)
334+
}
333335
_ => unreachable!(),
334336
}
335337
}
@@ -448,7 +450,11 @@ impl<'de> de::Deserializer<'de> for Config {
448450
where
449451
V: de::Visitor<'de>,
450452
{
451-
visitor.visit_enum(EnumAccess{ value: self.cache, name, variants })
453+
visitor.visit_enum(EnumAccess {
454+
value: self.cache,
455+
name,
456+
variants,
457+
})
452458
}
453459

454460
forward_to_deserialize_any! {

src/error.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,12 @@ impl ConfigError {
131131
unexpected,
132132
expected,
133133
key,
134-
} => {
135-
ConfigError::Type {
136-
origin,
137-
unexpected,
138-
expected,
139-
key: Some(concat(key)),
140-
}
141-
}
134+
} => ConfigError::Type {
135+
origin,
136+
unexpected,
137+
expected,
138+
key: Some(concat(key)),
139+
},
142140
ConfigError::NotFound(key) => ConfigError::NotFound(concat(Some(key))),
143141
_ => self,
144142
}
@@ -210,7 +208,7 @@ impl fmt::Display for ConfigError {
210208
}
211209
}
212210

213-
impl Error for ConfigError { }
211+
impl Error for ConfigError {}
214212

215213
impl de::Error for ConfigError {
216214
fn custom<T: fmt::Display>(msg: T) -> Self {

src/file/format/ini.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,13 @@ pub fn parse(
1515
Some(ref sec) => {
1616
let mut sec_map: HashMap<String, Value> = HashMap::new();
1717
for (k, v) in prop.iter() {
18-
sec_map.insert(
19-
k.clone(),
20-
Value::new(uri, ValueKind::String(v.clone())),
21-
);
18+
sec_map.insert(k.clone(), Value::new(uri, ValueKind::String(v.clone())));
2219
}
23-
map.insert(
24-
sec.clone(),
25-
Value::new(uri, ValueKind::Table(sec_map)),
26-
);
20+
map.insert(sec.clone(), Value::new(uri, ValueKind::Table(sec_map)));
2721
}
2822
None => {
2923
for (k, v) in prop.iter() {
30-
map.insert(
31-
k.clone(),
32-
Value::new(uri, ValueKind::String(v.clone())),
33-
);
24+
map.insert(k.clone(), Value::new(uri, ValueKind::String(v.clone())));
3425
}
3526
}
3627
}

src/file/format/json.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ fn from_json_value(uri: Option<&String>, value: &serde_json::Value) -> Value {
2222
match *value {
2323
serde_json::Value::String(ref value) => Value::new(uri, ValueKind::String(value.clone())),
2424

25-
serde_json::Value::Number(ref value) => if let Some(value) = value.as_i64() {
26-
Value::new(uri, ValueKind::Integer(value))
27-
} else if let Some(value) = value.as_f64() {
28-
Value::new(uri, ValueKind::Float(value))
29-
} else {
30-
unreachable!();
31-
},
25+
serde_json::Value::Number(ref value) => {
26+
if let Some(value) = value.as_i64() {
27+
Value::new(uri, ValueKind::Integer(value))
28+
} else if let Some(value) = value.as_f64() {
29+
Value::new(uri, ValueKind::Float(value))
30+
} else {
31+
unreachable!();
32+
}
33+
}
3234

3335
serde_json::Value::Bool(value) => Value::new(uri, ValueKind::Boolean(value)),
3436

src/file/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use value::Value;
1010
pub use self::format::FileFormat;
1111
use self::source::FileSource;
1212

13-
pub use self::source::string::FileSourceString;
1413
pub use self::source::file::FileSourceFile;
14+
pub use self::source::string::FileSourceString;
1515

1616
#[derive(Clone, Debug)]
1717
pub struct File<T>
@@ -119,9 +119,6 @@ where
119119
// Parse the string using the given format
120120
format
121121
.parse(uri.as_ref(), &contents)
122-
.map_err(|cause| ConfigError::FileParse {
123-
uri,
124-
cause,
125-
})
122+
.map_err(|cause| ConfigError::FileParse { uri, cause })
126123
}
127124
}

src/file/source/file.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,27 @@ impl FileSourceFile {
5858
}
5959

6060
match format_hint {
61-
Some(format) => for ext in format.extensions() {
62-
filename.set_extension(ext);
63-
64-
if filename.is_file() {
65-
return Ok((filename, format));
66-
}
67-
},
68-
69-
None => for (format, extensions) in ALL_EXTENSIONS.iter() {
61+
Some(format) => {
7062
for ext in format.extensions() {
7163
filename.set_extension(ext);
7264

7365
if filename.is_file() {
74-
return Ok((filename, *format));
66+
return Ok((filename, format));
7567
}
7668
}
77-
},
69+
}
70+
71+
None => {
72+
for (format, extensions) in ALL_EXTENSIONS.iter() {
73+
for ext in format.extensions() {
74+
filename.set_extension(ext);
75+
76+
if filename.is_file() {
77+
return Ok((filename, *format));
78+
}
79+
}
80+
}
81+
}
7882
}
7983

8084
Err(Box::new(io::Error::new(

src/path/mod.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -151,34 +151,30 @@ impl Expression {
151151
_ => None,
152152
},
153153

154-
Expression::Subscript(ref expr, index) => {
155-
match expr.get_mut_forcibly(root) {
156-
Some(value) => {
157-
match value.kind {
158-
ValueKind::Array(_) => (),
159-
_ => *value = Vec::<Value>::new().into(),
160-
}
161-
162-
match value.kind {
163-
ValueKind::Array(ref mut array) => {
164-
let index = sindex_to_uindex(index, array.len());
154+
Expression::Subscript(ref expr, index) => match expr.get_mut_forcibly(root) {
155+
Some(value) => {
156+
match value.kind {
157+
ValueKind::Array(_) => (),
158+
_ => *value = Vec::<Value>::new().into(),
159+
}
165160

166-
if index >= array.len() {
167-
array.resize(
168-
(index + 1) as usize,
169-
Value::new(None, ValueKind::Nil),
170-
);
171-
}
161+
match value.kind {
162+
ValueKind::Array(ref mut array) => {
163+
let index = sindex_to_uindex(index, array.len());
172164

173-
Some(&mut array[index])
165+
if index >= array.len() {
166+
array
167+
.resize((index + 1) as usize, Value::new(None, ValueKind::Nil));
174168
}
175169

176-
_ => None,
170+
Some(&mut array[index])
177171
}
172+
173+
_ => None,
178174
}
179-
_ => None,
180175
}
181-
}
176+
_ => None,
177+
},
182178
}
183179
}
184180

@@ -246,10 +242,7 @@ impl Expression {
246242
if let ValueKind::Array(ref mut array) = parent.kind {
247243
let uindex = sindex_to_uindex(index, array.len());
248244
if uindex >= array.len() {
249-
array.resize(
250-
(uindex + 1) as usize,
251-
Value::new(None, ValueKind::Nil),
252-
);
245+
array.resize((uindex + 1) as usize, Value::new(None, ValueKind::Nil));
253246
}
254247

255248
array[uindex] = value;

src/path/parser.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
use super::Expression;
22
use nom::{
3-
IResult, Err,
4-
error::ErrorKind,
5-
bytes::complete::{is_a, tag},
6-
character::complete::{char, digit1, space0},
7-
sequence::{delimited, pair, preceded},
8-
branch::alt,
9-
combinator::{map, map_res, opt, recognize},
3+
branch::alt,
4+
bytes::complete::{is_a, tag},
5+
character::complete::{char, digit1, space0},
6+
combinator::{map, map_res, opt, recognize},
7+
error::ErrorKind,
8+
sequence::{delimited, pair, preceded},
9+
Err, IResult,
1010
};
1111
use std::str::{from_utf8, FromStr};
1212

1313
fn raw_ident(i: &str) -> IResult<&str, String> {
14-
map(is_a(
15-
"abcdefghijklmnopqrstuvwxyz \
14+
map(
15+
is_a(
16+
"abcdefghijklmnopqrstuvwxyz \
1617
ABCDEFGHIJKLMNOPQRSTUVWXYZ \
1718
0123456789 \
18-
_-"
19-
), |s:&str| s.to_string())(i)
19+
_-",
20+
),
21+
|s: &str| s.to_string(),
22+
)(i)
2023
}
2124

2225
fn integer(i: &str) -> IResult<&str, isize> {
23-
map_res(
24-
delimited(
25-
space0,
26-
recognize(pair(opt(tag("-")), digit1)),
27-
space0
28-
),
29-
FromStr::from_str
30-
)(i)
26+
map_res(
27+
delimited(space0, recognize(pair(opt(tag("-")), digit1)), space0),
28+
FromStr::from_str,
29+
)(i)
3130
}
3231

3332
fn ident(i: &str) -> IResult<&str, Expression> {
34-
map(raw_ident, Expression::Identifier)(i)
33+
map(raw_ident, Expression::Identifier)(i)
3534
}
3635

3736
fn postfix<'a>(expr: Expression) -> impl Fn(&'a str) -> IResult<&'a str, Expression> {
38-
let e2 = expr.clone();
39-
let child = map(preceded(tag("."), raw_ident), move |id| Expression::Child(Box::new(expr.clone()), id));
37+
let e2 = expr.clone();
38+
let child = map(preceded(tag("."), raw_ident), move |id| {
39+
Expression::Child(Box::new(expr.clone()), id)
40+
});
4041

41-
let subscript = map(delimited(char('['), integer, char(']')), move |num| Expression::Subscript(Box::new(e2.clone()), num));
42+
let subscript = map(delimited(char('['), integer, char(']')), move |num| {
43+
Expression::Subscript(Box::new(e2.clone()), num)
44+
});
4245

43-
alt((
44-
child,
45-
subscript
46-
))
46+
alt((child, subscript))
4747
}
4848

4949
pub fn from_str(input: &str) -> Result<Expression, ErrorKind> {
@@ -72,10 +72,10 @@ pub fn from_str(input: &str) -> Result<Expression, ErrorKind> {
7272
}
7373

7474
pub fn to_error_kind(e: Err<(&str, ErrorKind)>) -> ErrorKind {
75-
match e {
76-
Err::Incomplete(_) => ErrorKind::Complete,
77-
Err::Failure((_, e)) | Err::Error((_, e)) => e,
78-
}
75+
match e {
76+
Err::Incomplete(_) => ErrorKind::Complete,
77+
Err::Failure((_, e)) | Err::Error((_, e)) => e,
78+
}
7979
}
8080

8181
#[cfg(test)]

0 commit comments

Comments
 (0)