Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 63ae238

Browse files
authored
Merge pull request #10 from mkmik/constructor
Switch to ::new constructor style
2 parents 53d4049 + eac1ab9 commit 63ae238

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/matchers.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ pub struct Child {
3737
name: String,
3838
}
3939

40-
pub fn new_child_matcher(name: String) -> Child {
41-
Child { name }
40+
impl Child {
41+
pub fn new(name: String) -> Self {
42+
Child { name }
43+
}
4244
}
4345

4446
impl Matcher for Child {
@@ -51,8 +53,10 @@ pub struct Union {
5153
elements: Vec<Box<dyn Matcher>>,
5254
}
5355

54-
pub fn new_union(elements: Vec<Box<dyn Matcher>>) -> Union {
55-
Union { elements }
56+
impl Union {
57+
pub fn new(elements: Vec<Box<dyn Matcher>>) -> Self {
58+
Union { elements }
59+
}
5660
}
5761

5862
impl Matcher for Union {

src/parser.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn parse_dot_child_matcher(
6666
let mut ms: Vec<Box<dyn matchers::Matcher>> = Vec::new();
6767
for r in matcher_rule.into_inner() {
6868
if let Rule::childName = r.as_rule() {
69-
ms.push(Box::new(matchers::new_child_matcher(r.as_str().to_owned())));
69+
ms.push(Box::new(matchers::Child::new(r.as_str().to_owned())));
7070
}
7171
}
7272
ms
@@ -81,19 +81,19 @@ fn parse_union(matcher_rule: pest::iterators::Pair<Rule>) -> Vec<Box<dyn matcher
8181
}
8282
}
8383
}
84-
vec![Box::new(matchers::new_union(ms))]
84+
vec![Box::new(matchers::Union::new(ms))]
8585
}
8686

8787
fn parse_union_child(matcher_rule: pest::iterators::Pair<Rule>) -> Vec<Box<dyn matchers::Matcher>> {
8888
let mut ms: Vec<Box<dyn matchers::Matcher>> = Vec::new();
8989
for r in matcher_rule.into_inner() {
9090
match r.as_rule() {
9191
Rule::doubleInner => {
92-
ms.push(Box::new(matchers::new_child_matcher(unescape(r.as_str()))));
92+
ms.push(Box::new(matchers::Child::new(unescape(r.as_str()))));
9393
}
9494

9595
Rule::singleInner => {
96-
ms.push(Box::new(matchers::new_child_matcher(unescape(r.as_str()))));
96+
ms.push(Box::new(matchers::Child::new(unescape(r.as_str()))));
9797
}
9898

9999
_ => (),

0 commit comments

Comments
 (0)