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

Avoid using dyn Path when not necessary #16

Merged
merged 1 commit into from
Oct 6, 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
2 changes: 1 addition & 1 deletion src/jsonpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ impl std::fmt::Display for SyntaxError {
}
}

pub fn parse(selector: &str) -> Result<Box<dyn Path + '_>, SyntaxError> {
pub fn parse(selector: &str) -> Result<impl Path, SyntaxError> {
parser::parse(selector).map_err(|m| SyntaxError { message: m })
}
4 changes: 2 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::pest::Parser;
#[grammar = "grammar.pest"]
struct PathParser;

pub fn parse(selector: &str) -> Result<Box<dyn path::Path + '_>, String> {
pub fn parse(selector: &str) -> Result<impl path::Path, String> {
let selector_rule = PathParser::parse(Rule::selector, selector)
.map_err(|e| format!("{}", e))?
.next()
Expand All @@ -33,7 +33,7 @@ pub fn parse(selector: &str) -> Result<Box<dyn path::Path + '_>, String> {
}
}

Ok(Box::new(path::new(ms)))
Ok(path::new(ms))
}

fn parse_matcher(matcher_rule: pest::iterators::Pair<Rule>) -> Vec<Box<dyn matchers::Matcher>> {
Expand Down
2 changes: 1 addition & 1 deletion tests/cts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down