From a89fd267b759c02c94437e94592ef4cb1d793ccf Mon Sep 17 00:00:00 2001 From: Marko Mikulicic Date: Thu, 1 Oct 2020 13:08:55 +0200 Subject: [PATCH] Controversial lifetime simplifications I'm more than half way through the rust book and according to the lifetime elision rules described there we could simplify some of the signatures. While on one hand being explicit is good, there is an argument in favour of simplifying when possible: adding unnecessary annotations (lifetime or type decls) is bound to draw some attention when the next developer reads the code; they might pause to think why would that be necessary and it might thus cause distraction. --- src/jsonpath.rs | 2 +- src/matchers.rs | 4 ++-- src/parser.rs | 2 +- src/path.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/jsonpath.rs b/src/jsonpath.rs index 19a2dac..e65c958 100644 --- a/src/jsonpath.rs +++ b/src/jsonpath.rs @@ -18,6 +18,6 @@ impl std::fmt::Display for SyntaxError { } } -pub fn parse<'a>(selector: &'a str) -> Result, SyntaxError> { +pub fn parse(selector: &str) -> Result, SyntaxError> { parser::parse(selector).map_err(|m| SyntaxError { message: m }) } diff --git a/src/matchers.rs b/src/matchers.rs index 1bbc488..288df1e 100644 --- a/src/matchers.rs +++ b/src/matchers.rs @@ -23,7 +23,7 @@ pub trait Matcher { pub struct RootSelector {} impl Matcher for RootSelector { - fn select<'a>(&'a self, node: &'a Value) -> Iter<'a> { + fn select<'a>(&self, node: &'a Value) -> Iter<'a> { Box::new(iter::once(node)) } } @@ -53,7 +53,7 @@ impl Child { } impl Matcher for Child { - fn select<'a>(&'a self, node: &'a Value) -> Iter<'a> { + fn select<'a>(&self, node: &'a Value) -> Iter<'a> { Box::new(node.get(&self.name).into_iter()) } } diff --git a/src/parser.rs b/src/parser.rs index 626a23c..7096728 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -12,7 +12,7 @@ use crate::pest::Parser; #[grammar = "grammar.pest"] struct PathParser; -pub fn parse<'a>(selector: &'a str) -> Result, String> { +pub fn parse(selector: &str) -> Result, String> { let selector_rule = PathParser::parse(Rule::selector, selector) .map_err(|e| format!("{}", e))? .next() diff --git a/src/path.rs b/src/path.rs index a02dd64..3c4d234 100644 --- a/src/path.rs +++ b/src/path.rs @@ -19,7 +19,7 @@ struct SelectorPath { matchers: Vec>, } -pub fn new<'a>(matchers: Vec>) -> impl Path + 'a { +pub fn new(matchers: Vec>) -> impl Path { SelectorPath { matchers } }