Skip to content

Commit

Permalink
chore: expose some symbol to help user use JsonLike trait (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
paomian authored Nov 2, 2024
1 parent 10f21aa commit 5c41200
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion src/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -111,7 +112,7 @@ impl JsonLike for Value {
self.get(key)
}

fn itre(&self, pref: String) -> Vec<JsonPathValue<'_, Self>> {
fn itre(&self, pref: String) -> Vec<JsonPathValue<Self>> {
let res = match self {
Value::Array(elems) => {
let mut res = vec![];
Expand All @@ -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())),
Expand Down
2 changes: 1 addition & 1 deletion src/path/top.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<T> FnPath<T> {

impl<'a, T> Path<'a> for FnPath<T>
where
T: JsonLike + 'static,
T: JsonLike,
{
type Data = T;

Expand Down

0 comments on commit 5c41200

Please sign in to comment.