From 4238e91775e3645ea7f850e440c4fd33a649d28c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Sun, 9 Jun 2024 23:15:41 +0200 Subject: [PATCH] provide a minimal example code, fix clippy issues and harden CI to verify everything --- .github/workflows/ci.yml | 2 +- benches/equal.rs | 4 ++-- benches/regex.rs | 6 +++--- examples/hello-world.rs | 13 +++++++++++++ src/parser/parser.rs | 2 ++ 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 examples/hello-world.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66f5835..b04abc1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: profile: minimal toolchain: stable components: clippy - - run: cargo clippy --workspace --tests --all-features -- -D warnings + - run: cargo clippy --workspace --all-targets --all-features -- -D warnings test: runs-on: ubuntu-latest diff --git a/benches/equal.rs b/benches/equal.rs index 10104dc..134cea7 100644 --- a/benches/equal.rs +++ b/benches/equal.rs @@ -8,7 +8,7 @@ struct SearchData { path: JsonPathInst, } -const PATH: &'static str = "$.[?(@.author == 'abcd(Rees)')]"; +const PATH: &str = "$.[?(@.author == 'abcd(Rees)')]"; fn equal_perf_test_with_reuse(cfg: &SearchData) { let _v = jsonpath_rust::find(&cfg.path, &cfg.json); @@ -33,7 +33,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { b.iter(|| equal_perf_test_with_reuse(&data)) }); c.bench_function("equal bench without reuse", |b| { - b.iter(|| equal_perf_test_without_reuse()) + b.iter(equal_perf_test_without_reuse) }); } diff --git a/benches/regex.rs b/benches/regex.rs index 6e0941d..901b688 100644 --- a/benches/regex.rs +++ b/benches/regex.rs @@ -8,7 +8,7 @@ struct SearchData { path: JsonPathInst, } -const PATH: &'static str = "$.[?(@.author ~= '.*(?i)d\\(Rees\\)')]"; +const PATH: &str = "$.[?(@.author ~= '.*(?i)d\\(Rees\\)')]"; fn regex_perf_test_with_reuse(cfg: &SearchData) { let _v = jsonpath_rust::find(&cfg.path, &cfg.json); @@ -37,10 +37,10 @@ pub fn criterion_benchmark(c: &mut Criterion) { b.iter(|| regex_perf_test_with_reuse(&data)) }); c.bench_function("regex bench without reuse", |b| { - b.iter(|| regex_perf_test_without_reuse()) + b.iter(regex_perf_test_without_reuse) }); c.bench_function("JsonPathInst generation", |b| { - b.iter(|| json_path_inst_compiling()) + b.iter(json_path_inst_compiling) }); } diff --git a/examples/hello-world.rs b/examples/hello-world.rs new file mode 100644 index 0000000..8fff1f7 --- /dev/null +++ b/examples/hello-world.rs @@ -0,0 +1,13 @@ +use jsonpath_rust::JsonPathInst; +use serde_json::json; +use std::str::FromStr; + +fn main() { + let data = json!({ + "Hello":"World", + "Good":"Bye", + }); + let path = JsonPathInst::from_str("$.Hello").unwrap(); + let search_result = jsonpath_rust::find(&path, &data); + println!("Hello, {}", search_result); +} diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 4155b7e..086ba4c 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -1,3 +1,5 @@ +#![allow(clippy::empty_docs)] + use crate::parser::errors::JsonPathParserError::ParserError; use crate::parser::errors::{parser_err, JsonPathParserError}; use crate::parser::model::FilterExpression::{And, Not, Or};