Skip to content

Commit

Permalink
make parser public (#39)
Browse files Browse the repository at this point in the history
* make parser public

* add v

* change methods to tryFrom

* correct formatting

* add next formatting
  • Loading branch information
besok authored Mar 22, 2023
1 parent 414edde commit bd641d6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@
* add ..*
* **`0.2.5`**
* build for tags
* **`0.2.6`**
* make parser mod public
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "jsonpath-rust"
description = "The library provides the basic functionality to find the set of the data according to the filtering query."
version = "0.2.5"
version = "0.2.6"
authors = ["BorisZhguchev <zhguchev@gmail.com>"]
edition = "2018"
license-file = "LICENSE"
Expand Down
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ use crate::parser::model::JsonPath;
use crate::parser::parser::parse_json_path;
use crate::path::{json_path_instance, PathInstance};
use serde_json::Value;
use std::convert::TryInto;
use std::fmt::Debug;
use std::str::FromStr;

mod parser;
mod path;
pub mod parser;
pub mod path;

#[macro_use]
extern crate pest_derive;
Expand Down Expand Up @@ -169,7 +170,9 @@ impl FromStr for JsonPathInst {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
JsonPath::from_str(s).map(|inner| JsonPathInst { inner })
Ok(JsonPathInst {
inner: s.try_into()?,
})
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
//! The module grammar denotes the structure of the parsing grammar
mod macros;
pub(crate) mod model;
pub mod model;
#[allow(clippy::module_inception)]
pub(crate) mod parser;
pub mod parser;
11 changes: 7 additions & 4 deletions src/parser/model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::parse_json_path;
use serde_json::Value;
use std::convert::TryFrom;

/// The basic structures for parsing json paths.
/// The common logic of the structures pursues to correspond the internal parsing structure.
Expand Down Expand Up @@ -27,12 +28,14 @@ pub enum JsonPath {
Fn(Function),
}

impl JsonPath {
/// allows to create an JsonPath from string
pub fn from_str(v: &str) -> Result<JsonPath, String> {
parse_json_path(v).map_err(|e| e.to_string())
impl TryFrom<&str> for JsonPath {
type Error = String;

fn try_from(value: &str) -> Result<Self, Self::Error> {
parse_json_path(value).map_err(|e| e.to_string())
}
}

#[derive(Debug, PartialEq, Clone)]
pub enum Function {
/// length()
Expand Down

0 comments on commit bd641d6

Please sign in to comment.