diff --git a/crates/rsonpath-lib/src/engine/recursive.rs b/crates/rsonpath-lib/src/engine/recursive.rs index b841aa17..af143b58 100644 --- a/crates/rsonpath-lib/src/engine/recursive.rs +++ b/crates/rsonpath-lib/src/engine/recursive.rs @@ -17,7 +17,7 @@ use crate::engine::{Compiler, Engine}; use crate::input::Input; use crate::query::automaton::{Automaton, State, TransitionLabel}; use crate::query::error::CompilerError; -use crate::query::nonnegative_array_index::NonNegativeArrayIndex; +use crate::query::NonNegativeArrayIndex; use crate::query::{JsonPathQuery, Label}; use crate::result::QueryResult; use crate::BLOCK_SIZE; diff --git a/crates/rsonpath-lib/src/input/owned.rs b/crates/rsonpath-lib/src/input/owned.rs index 7d6a68bf..aa44e88a 100644 --- a/crates/rsonpath-lib/src/input/owned.rs +++ b/crates/rsonpath-lib/src/input/owned.rs @@ -132,12 +132,14 @@ impl From> for OwnedBytes { } impl> From<&T> for OwnedBytes { + #[inline] fn from(value: &T) -> Self { Self::new(value) } } impl From<&str> for OwnedBytes { + #[inline] fn from(value: &str) -> Self { Self::from(&value.as_bytes()) } diff --git a/crates/rsonpath-lib/src/query.rs b/crates/rsonpath-lib/src/query.rs index ca64f892..2e2dd1f5 100644 --- a/crates/rsonpath-lib/src/query.rs +++ b/crates/rsonpath-lib/src/query.rs @@ -34,10 +34,11 @@ pub mod automaton; pub mod builder; pub mod error; mod label; -pub mod nonnegative_array_index; +mod nonnegative_array_index; mod parser; use aligners::alignment; pub use label::Label; +pub use nonnegative_array_index::NonNegativeArrayIndex; use log::*; use std::fmt::{self, Display}; @@ -74,7 +75,7 @@ pub enum JsonPathQueryNode { use JsonPathQueryNode::*; -use self::{error::ParserError, nonnegative_array_index::NonNegativeArrayIndex}; +use self::error::ParserError; impl JsonPathQueryNode { /// Retrieve the child of the node or `None` if it is the last one @@ -266,7 +267,7 @@ impl JsonPathQueryNodeType for JsonPathQueryNode { #[inline(always)] fn array_index(&self) -> Option<&NonNegativeArrayIndex> { match self { - ArrayIndexChild(i, _) | ArrayIndexDescendant(i,_) => Some(i), + ArrayIndexChild(i, _) | ArrayIndexDescendant(i, _) => Some(i), Child(_, _) | Descendant(_, _) | Root(_) | AnyChild(_) | AnyDescendant(_) => None, } } diff --git a/crates/rsonpath-lib/src/query/automaton.rs b/crates/rsonpath-lib/src/query/automaton.rs index 02d90f60..d92ce2a9 100644 --- a/crates/rsonpath-lib/src/query/automaton.rs +++ b/crates/rsonpath-lib/src/query/automaton.rs @@ -21,7 +21,9 @@ pub struct Automaton<'q> { /// Represent the distinct methods of moving on a match between states. #[derive(Debug, Copy, PartialEq, Clone, Eq)] pub enum TransitionLabel<'q> { + /// Wraps a textual field [`Label`] in a JSON object. ObjectMember(&'q Label), + /// Wraps an array index [`NonNegativeArrayIndex`] in a JSON object. ArrayIndex(NonNegativeArrayIndex), } @@ -38,6 +40,7 @@ impl<'q> TransitionLabel<'q> { } } + ///Return the textual [`Label`] being wrapped if so. Returns [`None`] otherwise. #[must_use] #[inline(always)] pub fn get_label(&self) -> Option<&Label> { @@ -47,6 +50,7 @@ impl<'q> TransitionLabel<'q> { } } + /// Consumes the [`TransitionLabel`] and gives the wrapped [`Label`], if so. Returns [`None`] otherwise. #[must_use] #[inline(always)] pub fn get_label_owned(self) -> Option<&'q Label> { @@ -56,12 +60,14 @@ impl<'q> TransitionLabel<'q> { } } + /// Wraps a [`Label`] in a [`TransitionLabel`]. #[must_use] #[inline(always)] pub fn new_object_member(label: &'q Label) -> Self { TransitionLabel::ObjectMember(label) } + /// Wraps a [`NonNegativeArrayIndex`] in a [`TransitionLabel`]. #[must_use] #[inline(always)] pub fn new_array_index(label: NonNegativeArrayIndex) -> Self { diff --git a/crates/rsonpath-lib/src/query/nonnegative_array_index.rs b/crates/rsonpath-lib/src/query/nonnegative_array_index.rs index bf2d42f9..2863b6ae 100644 --- a/crates/rsonpath-lib/src/query/nonnegative_array_index.rs +++ b/crates/rsonpath-lib/src/query/nonnegative_array_index.rs @@ -5,11 +5,20 @@ use std::fmt::{self, Display, Formatter}; /// /// Represents a specific location from the front of the list in a json array. /// Provides the [IETF-conforming index value](https://www.rfc-editor.org/rfc/rfc7493.html#section-2). Values are \[0, (2^53)-1]. +/// # Examples +/// +/// ``` +/// # use rsonpath_lib::query::NonNegativeArrayIndex; +/// +/// let idx = NonNegativeArrayIndex::new(2); +/// +/// assert_eq!(idx.get_index(), 2); +/// ``` #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub struct NonNegativeArrayIndex(u64); /// The upper inclusive bound on index values. -pub const ARRAY_INDEX_ULIMIT: u64 = (1 << 53) - 1; +pub(crate) const ARRAY_INDEX_ULIMIT: u64 = (1 << 53) - 1; impl TryFrom for NonNegativeArrayIndex { type Error = ArrayIndexError;