From 668b6265611be2247e24d3f3b1e8c179ccbe459e Mon Sep 17 00:00:00 2001 From: Boris Zhguchev Date: Tue, 9 Jan 2024 23:14:33 +0100 Subject: [PATCH] fix bugs --- Cargo.toml | 3 +-- README.md | 1 + src/lib.rs | 2 +- src/path/json.rs | 12 ++++++------ src/path/top.rs | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 241762e..832e1ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,9 @@ [package] name = "jsonpath-rust" description = "The library provides the basic functionality to find the set of the data according to the filtering query." -version = "0.3.5" +version = "0.4.0" authors = ["BorisZhguchev "] edition = "2018" -license = "MIT" license-file = "LICENSE" homepage = "https://github.com/besok/jsonpath-rust" repository = "https://github.com/besok/jsonpath-rust" diff --git a/README.md b/README.md index d87e52d..8384f80 100644 --- a/README.md +++ b/README.md @@ -432,5 +432,6 @@ TBD ## How to update version - update files + - commit them - add tag `git tag -a v -m "message"` - git push origin \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index cb3be69..aba2969 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1195,7 +1195,7 @@ mod tests { .expect("the path is correct"); let results = query.find_slice(&json); - let v = results.get(0).expect("to get value"); + let v = results.first().expect("to get value"); // V can be implicitly converted to &Value test_coercion(v); diff --git a/src/path/json.rs b/src/path/json.rs index 467ecd0..83d9a7e 100644 --- a/src/path/json.rs +++ b/src/path/json.rs @@ -5,7 +5,7 @@ use serde_json::Value; /// The method expects to get a number on the right side and array or string or object on the left /// where the number of characters, elements or fields will be compared respectively. pub fn size(left: Vec<&Value>, right: Vec<&Value>) -> bool { - if let Some(Value::Number(n)) = right.get(0) { + if let Some(Value::Number(n)) = right.first() { if let Some(sz) = n.as_f64() { for el in left.iter() { match el { @@ -32,7 +32,7 @@ pub fn sub_set_of(left: Vec<&Value>, right: Vec<&Value>) -> bool { } if let Some(elems) = left.first().and_then(|e| e.as_array()) { - if let Some(Value::Array(right_elems)) = right.get(0) { + if let Some(Value::Array(right_elems)) = right.first() { if right_elems.is_empty() { return false; } @@ -65,7 +65,7 @@ pub fn any_of(left: Vec<&Value>, right: Vec<&Value>) -> bool { return false; } - if let Some(Value::Array(elems)) = right.get(0) { + if let Some(Value::Array(elems)) = right.first() { if elems.is_empty() { return false; } @@ -98,7 +98,7 @@ pub fn regex(left: Vec<&Value>, right: Vec<&Value>) -> bool { return false; } - match right.get(0) { + match right.first() { Some(Value::String(str)) => { if let Ok(regex) = Regex::new(str) { for el in left.iter() { @@ -121,7 +121,7 @@ pub fn inside(left: Vec<&Value>, right: Vec<&Value>) -> bool { return false; } - match right.get(0) { + match right.first() { Some(Value::Array(elems)) => { for el in left.iter() { if elems.contains(el) { @@ -147,7 +147,7 @@ pub fn inside(left: Vec<&Value>, right: Vec<&Value>) -> bool { /// ensure the number on the left side is less the number on the right side pub fn less(left: Vec<&Value>, right: Vec<&Value>) -> bool { if left.len() == 1 && right.len() == 1 { - match (left.get(0), right.get(0)) { + match (left.first(), right.first()) { (Some(Value::Number(l)), Some(Value::Number(r))) => l .as_f64() .and_then(|v1| r.as_f64().map(|v2| v1 < v2)) diff --git a/src/path/top.rs b/src/path/top.rs index 090ae38..1d3fbf9 100644 --- a/src/path/top.rs +++ b/src/path/top.rs @@ -117,7 +117,7 @@ impl<'a> Path<'a> for FnPath { _ => NoValue, }; - match input.get(0) { + match input.first() { Some(v) => match v { NewValue(d) => take_len(d), Slice(s, _) => take_len(s),