From 9d5c43e9b663f4e48fe168414e637673aea4aa43 Mon Sep 17 00:00:00 2001 From: paomian Date: Fri, 1 Nov 2024 20:24:34 +0800 Subject: [PATCH] chore: expose some symbol to help user use JsonLike trait --- src/lib.rs | 6 +++--- src/path/mod.rs | 4 +++- src/path/top.rs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1d11ede..ce687dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -99,7 +99,7 @@ //! [`there`]: https://goessner.net/articles/JsonPath/ pub use parser::model::JsonPath; -use parser::JsonPathParserError; +pub use parser::JsonPathParserError; use serde_json::Value; use std::fmt::Debug; use std::ops::Deref; @@ -263,10 +263,10 @@ macro_rules! jp_v { /// Represents the path of the found json data type JsPathStr = String; -pub(crate) fn jsp_idx(prefix: &str, idx: usize) -> String { +pub fn jsp_idx(prefix: &str, idx: usize) -> String { format!("{}[{}]", prefix, idx) } -pub(crate) fn jsp_obj(prefix: &str, key: &str) -> String { +pub fn jsp_obj(prefix: &str, key: &str) -> String { format!("{}.['{}']", prefix, key) } diff --git a/src/path/mod.rs b/src/path/mod.rs index f4322f0..b15b6ab 100644 --- a/src/path/mod.rs +++ b/src/path/mod.rs @@ -6,6 +6,7 @@ use serde_json::{json, Value}; use crate::parser::model::{Function, JsonPath, JsonPathIndex, Operand}; pub use crate::path::index::{ArrayIndex, ArraySlice, Current, FilterPath, UnionIndex}; +pub use crate::path::top::ObjectField; use crate::path::top::*; /// The module is in charge of processing [[JsonPathIndex]] elements @@ -111,7 +112,7 @@ impl JsonLike for Value { self.get(key) } - fn itre(&self, pref: String) -> Vec> { + fn itre(&self, pref: String) -> Vec> { let res = match self { Value::Array(elems) => { let mut res = vec![]; @@ -135,6 +136,7 @@ impl JsonLike for Value { res } } + fn array_len(&self) -> JsonPathValue<'static, Self> { match self { Value::Array(elems) => JsonPathValue::NewValue(json!(elems.len())), diff --git a/src/path/top.rs b/src/path/top.rs index 220fa79..8fe5e7a 100644 --- a/src/path/top.rs +++ b/src/path/top.rs @@ -150,7 +150,7 @@ impl FnPath { impl<'a, T> Path<'a> for FnPath where - T: JsonLike + 'static, + T: JsonLike, { type Data = T;