From bebe612bc3b228971507e1bd29e8681c6818774b Mon Sep 17 00:00:00 2001 From: Marko Mikulicic Date: Mon, 5 Oct 2020 11:40:20 +0200 Subject: [PATCH] Avoid using dyn Path when not necessary Advantage: call to the Disadvantage: callers need to bring path::Path explicitly in scope. This seems to be more idiomatic rust code, at least from what I understand reading https://rust-lang.github.io/rfcs/2113-dyn-trait-syntax.html --- src/jsonpath.rs | 2 +- src/parser.rs | 4 ++-- tests/cts.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jsonpath.rs b/src/jsonpath.rs index e65c958..72a7ce8 100644 --- a/src/jsonpath.rs +++ b/src/jsonpath.rs @@ -18,6 +18,6 @@ impl std::fmt::Display for SyntaxError { } } -pub fn parse(selector: &str) -> Result, SyntaxError> { +pub fn parse(selector: &str) -> Result { parser::parse(selector).map_err(|m| SyntaxError { message: m }) } diff --git a/src/parser.rs b/src/parser.rs index 7096728..a5843d0 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(selector: &str) -> Result, String> { +pub fn parse(selector: &str) -> Result { let selector_rule = PathParser::parse(Rule::selector, selector) .map_err(|e| format!("{}", e))? .next() @@ -33,7 +33,7 @@ pub fn parse(selector: &str) -> Result, String> { } } - Ok(Box::new(path::new(ms))) + Ok(path::new(ms)) } fn parse_matcher(matcher_rule: pest::iterators::Pair) -> Vec> { diff --git a/tests/cts.rs b/tests/cts.rs index 30b5de9..166fe55 100644 --- a/tests/cts.rs +++ b/tests/cts.rs @@ -6,7 +6,7 @@ #[cfg(test)] mod tests { - use jsonpath_reference_implementation::jsonpath; + use jsonpath_reference_implementation::{jsonpath, path::Path as _}; use serde::{Deserialize, Serialize}; use std::fs; use std::panic;