Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Forum](https://img.shields.io/badge/Forum-RedisJSON-blue)](https://forum.redislabs.com/c/modules/redisjson)
[![Discord](https://img.shields.io/discord/697882427875393627?style=flat-square)](https://discord.gg/QUkjSsk)

A JSONPath library for rust. The idea behind this library is that it can operate on any json representation as long as it implements the [`SelectValue`](src/select_value.rs) triat. The library has an implementation for [serde_json value](https://docs.serde.rs/serde_json/value/enum.Value.html) and [ivalue](https://docs.rs/tch/0.1.1/tch/enum.IValue.html).
A JSONPath library for rust. The idea behind this library is that it can operate on any json representation as long as it implements the [`SelectValue`](src/select_value.rs) trait. The library has an implementation for [serde_json value](https://docs.serde.rs/serde_json/value/enum.Value.html) and [ivalue](https://docs.rs/tch/0.1.1/tch/enum.IValue.html).

### Getting Started
Add the following to your cargo.toml
Expand Down
2 changes: 1 addition & 1 deletion src/grammer.pest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
literal = @{('a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | "-" | "_" | "`" | "~" | "+" | "#" | "%" | "$" | "^" | "/")+}
literal = @{('a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | "-" | "_" | "`" | "~" | "+" | "#" | "%" | "$" | "^" | "/" | ":")+}

string = _{("'" ~ (string_value) ~ "'") | ("\"" ~ (string_value) ~ "\"") | ("\"" ~ (string_value_escape_1) ~ "\"") | ("'" ~ (string_value_escape_2) ~ "'")}
string_escape = @{"\\"}
Expand Down
15 changes: 8 additions & 7 deletions src/json_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl SelectValue for Value {
fn get_long(&self) -> i64 {
match self {
Value::Number(n) => {
if n.is_i64() || n.is_u64() {
n.as_i64().unwrap()
if let Some(n) = n.as_i64() {
n
} else {
panic!("not a long");
}
Expand Down Expand Up @@ -155,9 +155,10 @@ impl SelectValue for IValue {
}

fn contains_key(&self, key: &str) -> bool {
match self.as_object() {
Some(o) => o.contains_key(key),
_ => false,
if let Some(o) = self.as_object() {
o.contains_key(key)
} else {
false
}
}

Expand Down Expand Up @@ -247,7 +248,7 @@ impl SelectValue for IValue {
}
}
_ => {
panic!("not a long");
panic!("not a number");
}
}
}
Expand All @@ -262,7 +263,7 @@ impl SelectValue for IValue {
}
}
_ => {
panic!("not a double");
panic!("not a number");
}
}
}
Expand Down
Loading