Skip to content

Commit ac3346c

Browse files
committed
cargo fmt
1 parent a1fe7f8 commit ac3346c

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/ast.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,33 @@ impl Selector {
8888
Value::Array(a) => Box::new(a.iter()),
8989
_ => Box::new(std::iter::empty()),
9090
},
91-
Selector::DescendantDotName(name) => Self::traverse(input, move |n: &'a Value| Box::new(n.get(name).into_iter())),
92-
Selector::DescendantDotWildcard => Self::traverse(input, move |n: &'a Value| Box::new(iter::once(n))),
93-
Selector::DescendantUnionElement(element) => Self::traverse(input, move |n: &'a Value| element.find(n)),
91+
Selector::DescendantDotName(name) => {
92+
Self::traverse(input, move |n: &'a Value| Box::new(n.get(name).into_iter()))
93+
}
94+
Selector::DescendantDotWildcard => {
95+
Self::traverse(input, move |n: &'a Value| Box::new(iter::once(n)))
96+
}
97+
Selector::DescendantUnionElement(element) => {
98+
Self::traverse(input, move |n: &'a Value| element.find(n))
99+
}
94100
}
95101
}
96102

97103
// traverse applies the given closure to all the descendants of the input value and
98104
// returns a nodelist.
99105
fn traverse<'a, F>(input: &'a Value, f: F) -> NodeList<'a>
100-
where F: Fn(&'a Value) -> NodeList<'a> + Copy + 'a {
106+
where
107+
F: Fn(&'a Value) -> NodeList<'a> + Copy + 'a,
108+
{
101109
match input {
102-
Value::Object(m) => Box::new(m.into_iter().flat_map(move |(_k, v)| (&f)(v).chain(Self::traverse::<'a>(v, f)))),
103-
Value::Array(a) => Box::new(a.iter().flat_map(move |v| (&f)(v).chain(Self::traverse::<'a>(v, f)))),
110+
Value::Object(m) => Box::new(
111+
m.into_iter()
112+
.flat_map(move |(_k, v)| (&f)(v).chain(Self::traverse::<'a>(v, f))),
113+
),
114+
Value::Array(a) => Box::new(
115+
a.iter()
116+
.flat_map(move |v| (&f)(v).chain(Self::traverse::<'a>(v, f))),
117+
),
104118
_ => Box::new(std::iter::empty()),
105119
}
106120
}

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn parse_selector(matcher_rule: pest::iterators::Pair<Rule>) -> Result<Selector,
4040
Rule::wildcardedDotChild => Selector::DotWildcard,
4141
Rule::namedDotChild => Selector::DotName(parse_child_name(r)),
4242
Rule::union => Selector::Union(parse_union_indices(r)?),
43-
Rule::descendant => parse_descendant(r)?,
43+
Rule::descendant => parse_descendant(r)?,
4444
_ => panic!("invalid parse tree {:?}", r),
4545
})
4646
}

tests/cts.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ mod tests {
9292
} else {
9393
if t.invalid_selector {
9494
// print failure message
95-
println!("{}: parsing `{}` failed with: {}", t.name, t.selector, path.err().expect("should be an error"));
95+
println!(
96+
"{}: parsing `{}` failed with: {}",
97+
t.name,
98+
t.selector,
99+
path.err().expect("should be an error")
100+
);
96101
} else {
97102
assert!(
98103
path.is_ok(),

0 commit comments

Comments
 (0)