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

Switch to ::new constructor style #10

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/matchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ pub struct Child {
name: String,
}

pub fn new_child_matcher(name: String) -> Child {
Child { name }
impl Child {
pub fn new(name: String) -> Self {
Child { name }
}
}

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

pub fn new_union(elements: Vec<Box<dyn Matcher>>) -> Union {
Union { elements }
impl Union {
pub fn new(elements: Vec<Box<dyn Matcher>>) -> Self {
Union { elements }
}
}

impl Matcher for Union {
Expand Down
8 changes: 4 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn parse_dot_child_matcher(
let mut ms: Vec<Box<dyn matchers::Matcher>> = Vec::new();
for r in matcher_rule.into_inner() {
if let Rule::childName = r.as_rule() {
ms.push(Box::new(matchers::new_child_matcher(r.as_str().to_owned())));
ms.push(Box::new(matchers::Child::new(r.as_str().to_owned())));
}
}
ms
Expand All @@ -81,19 +81,19 @@ fn parse_union(matcher_rule: pest::iterators::Pair<Rule>) -> Vec<Box<dyn matcher
}
}
}
vec![Box::new(matchers::new_union(ms))]
vec![Box::new(matchers::Union::new(ms))]
}

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

Rule::singleInner => {
ms.push(Box::new(matchers::new_child_matcher(unescape(r.as_str()))));
ms.push(Box::new(matchers::Child::new(unescape(r.as_str()))));
}

_ => (),
Expand Down