Skip to content

Commit ecb4e4d

Browse files
committed
clean perdantic warnings
1 parent 0509741 commit ecb4e4d

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

src/json_node.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,10 @@ impl SelectValue for IValue {
186186
}
187187

188188
fn len(&self) -> Option<usize> {
189-
if let Some(arr) = self.as_array() {
190-
Some(arr.len())
191-
} else {
192-
self.as_object().map(|obj| obj.len())
193-
}
189+
self.as_array().map_or_else(
190+
|| self.as_object().map(ijson::IObject::len),
191+
|arr| Some(arr.len()),
192+
)
194193
}
195194

196195
fn get_key<'a>(&'a self, key: &str) -> Option<&'a Self> {

src/json_path.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ impl std::fmt::Display for Rule {
4747
}
4848
}
4949

50-
pub(crate) fn compile(s: &str) -> Result<Query, QueryCompilationError> {
51-
let q = JsonPathParser::parse(Rule::query, s);
52-
match q {
50+
pub(crate) fn compile(path: &str) -> Result<Query, QueryCompilationError> {
51+
let query = JsonPathParser::parse(Rule::query, path);
52+
match query {
5353
Ok(q) => Ok(Query { query: q }),
5454
// pest::error::Error
5555
Err(e) => {
@@ -62,27 +62,27 @@ pub(crate) fn compile(s: &str) -> Result<Query, QueryCompilationError> {
6262
ref positives,
6363
ref negatives,
6464
} => {
65-
let positives = if !positives.is_empty() {
65+
let positives = if positives.is_empty() {
66+
None
67+
} else {
6668
Some(
6769
positives
6870
.iter()
6971
.map(|v| format!("{}", v))
7072
.collect::<Vec<_>>()
7173
.join(", "),
7274
)
73-
} else {
74-
None
7575
};
76-
let negatives = if !negatives.is_empty() {
76+
let negatives = if negatives.is_empty() {
77+
None
78+
} else {
7779
Some(
7880
negatives
7981
.iter()
8082
.map(|v| format!("{}", v))
8183
.collect::<Vec<_>>()
8284
.join(", "),
8385
)
84-
} else {
85-
None
8686
};
8787

8888
match (positives, negatives) {
@@ -98,10 +98,10 @@ pub(crate) fn compile(s: &str) -> Result<Query, QueryCompilationError> {
9898
pest::error::ErrorVariant::CustomError { ref message } => message.clone(),
9999
};
100100

101-
let final_msg = if pos == s.len() {
102-
format!("\"{} <<<<----\", {}.", s, msg)
101+
let final_msg = if pos == path.len() {
102+
format!("\"{} <<<<----\", {}.", path, msg)
103103
} else {
104-
format!("\"{} ---->>>> {}\", {}.", &s[..pos], &s[pos..], msg)
104+
format!("\"{} ---->>>> {}\", {}.", &path[..pos], &path[pos..], msg)
105105
};
106106
Err(QueryCompilationError {
107107
location: pos,
@@ -151,11 +151,11 @@ pub struct PTracker {
151151
}
152152
impl UserPathTracker for PTracker {
153153
fn add_str(&mut self, s: &str) {
154-
self.elemenets.push(PTrackerElement::Key(s.to_string()))
154+
self.elemenets.push(PTrackerElement::Key(s.to_string()));
155155
}
156156

157157
fn add_index(&mut self, i: usize) {
158-
self.elemenets.push(PTrackerElement::Index(i))
158+
self.elemenets.push(PTrackerElement::Index(i));
159159
}
160160

161161
fn to_string_path(self) -> Vec<String> {
@@ -192,21 +192,21 @@ struct PathTracker<'i, 'j> {
192192
element: PathTrackerElement<'i>,
193193
}
194194

195-
fn create_empty_trucker<'i, 'j>() -> PathTracker<'i, 'j> {
195+
const fn create_empty_trucker<'i, 'j>() -> PathTracker<'i, 'j> {
196196
PathTracker {
197197
father: None,
198198
element: PathTrackerElement::Root,
199199
}
200200
}
201201

202-
fn create_str_trucker<'i, 'j>(s: &'i str, father: &'j PathTracker<'i, 'j>) -> PathTracker<'i, 'j> {
202+
const fn create_str_trucker<'i, 'j>(s: &'i str, father: &'j PathTracker<'i, 'j>) -> PathTracker<'i, 'j> {
203203
PathTracker {
204204
father: Some(father),
205205
element: PathTrackerElement::Key(s),
206206
}
207207
}
208208

209-
fn create_index_trucker<'i, 'j>(
209+
const fn create_index_trucker<'i, 'j>(
210210
index: usize,
211211
father: &'j PathTracker<'i, 'j>,
212212
) -> PathTracker<'i, 'j> {
@@ -785,7 +785,7 @@ impl<'i, UPTG: UserPathTrackerGenerator> PathCalculator<'i, UPTG> {
785785

786786
fn populate_path_tracker<'k, 'l>(&self, pt: &PathTracker<'l, 'k>, upt: &mut UPTG::PT) {
787787
if let Some(f) = pt.father {
788-
self.populate_path_tracker(f, upt)
788+
self.populate_path_tracker(f, upt);
789789
}
790790
match pt.element {
791791
PathTrackerElement::Index(i) => upt.add_index(i),
@@ -820,18 +820,18 @@ impl<'i, UPTG: UserPathTrackerGenerator> PathCalculator<'i, UPTG> {
820820
calc_data,
821821
false,
822822
);
823-
self.calc_full_scan(pairs, json, path_tracker, calc_data)
823+
self.calc_full_scan(pairs, json, path_tracker, calc_data);
824824
}
825825
Rule::all => self.calc_all(pairs, json, path_tracker, calc_data),
826826
Rule::literal => self.calc_literal(pairs, curr, json, path_tracker, calc_data),
827827
Rule::string_list => {
828-
self.calc_strings(pairs, curr, json, path_tracker, calc_data)
828+
self.calc_strings(pairs, curr, json, path_tracker, calc_data);
829829
}
830830
Rule::numbers_list => {
831-
self.calc_indexes(pairs, curr, json, path_tracker, calc_data)
831+
self.calc_indexes(pairs, curr, json, path_tracker, calc_data);
832832
}
833833
Rule::numbers_range => {
834-
self.calc_range(pairs, curr, json, path_tracker, calc_data)
834+
self.calc_range(pairs, curr, json, path_tracker, calc_data);
835835
}
836836
Rule::filter => {
837837
if flat_arrays_on_filter && json.get_type() == SelectValueType::Array {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn create_with_generator<'i>(query: &'i Query<'i>) -> PathCalculator<'i, PTr
5454
}
5555

5656
/// Compile the given json path, compilation results can after be used
57-
/// to create PathCalculator calculator object to calculate json paths
57+
/// to create `PathCalculator` calculator object to calculate json paths
5858
pub fn compile(s: &str) -> Result<Query, QueryCompilationError> {
5959
json_path::compile(s)
6060
}

0 commit comments

Comments
 (0)