Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: expose some symbol to help user use JsonLike trait #76

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading