Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Zhguchev committed Jan 9, 2024
1 parent 1ee76aa commit 668b626
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <zhguchev@gmail.com>"]
edition = "2018"
license = "MIT"
license-file = "LICENSE"
homepage = "https://github.com/besok/jsonpath-rust"
repository = "https://github.com/besok/jsonpath-rust"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,5 +432,6 @@ TBD

## How to update version
- update files
- commit them
- add tag `git tag -a v<Version> -m "message"`
- git push origin <tag_name>
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/path/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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) {
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/path/top.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 668b626

Please sign in to comment.