Skip to content

Commit f423485

Browse files
committed
docs for NonNegativeArrayIndex and associated
1 parent 7695a35 commit f423485

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

crates/rsonpath-lib/src/engine/recursive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::engine::{Compiler, Engine};
1717
use crate::input::Input;
1818
use crate::query::automaton::{Automaton, State, TransitionLabel};
1919
use crate::query::error::CompilerError;
20-
use crate::query::nonnegative_array_index::NonNegativeArrayIndex;
20+
use crate::query::NonNegativeArrayIndex;
2121
use crate::query::{JsonPathQuery, Label};
2222
use crate::result::QueryResult;
2323
use crate::BLOCK_SIZE;

crates/rsonpath-lib/src/input/owned.rs

+2
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ impl From<Vec<u8>> for OwnedBytes {
132132
}
133133

134134
impl<T: AsRef<[u8]>> From<&T> for OwnedBytes {
135+
#[inline]
135136
fn from(value: &T) -> Self {
136137
Self::new(value)
137138
}
138139
}
139140

140141
impl From<&str> for OwnedBytes {
142+
#[inline]
141143
fn from(value: &str) -> Self {
142144
Self::from(&value.as_bytes())
143145
}

crates/rsonpath-lib/src/query.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ pub mod automaton;
3434
pub mod builder;
3535
pub mod error;
3636
mod label;
37-
pub mod nonnegative_array_index;
37+
mod nonnegative_array_index;
3838
mod parser;
3939
use aligners::alignment;
4040
pub use label::Label;
41+
pub use nonnegative_array_index::NonNegativeArrayIndex;
4142

4243
use log::*;
4344
use std::fmt::{self, Display};
@@ -74,7 +75,7 @@ pub enum JsonPathQueryNode {
7475

7576
use JsonPathQueryNode::*;
7677

77-
use self::{error::ParserError, nonnegative_array_index::NonNegativeArrayIndex};
78+
use self::error::ParserError;
7879

7980
impl JsonPathQueryNode {
8081
/// Retrieve the child of the node or `None` if it is the last one
@@ -266,7 +267,7 @@ impl JsonPathQueryNodeType for JsonPathQueryNode {
266267
#[inline(always)]
267268
fn array_index(&self) -> Option<&NonNegativeArrayIndex> {
268269
match self {
269-
ArrayIndexChild(i, _) | ArrayIndexDescendant(i,_) => Some(i),
270+
ArrayIndexChild(i, _) | ArrayIndexDescendant(i, _) => Some(i),
270271
Child(_, _) | Descendant(_, _) | Root(_) | AnyChild(_) | AnyDescendant(_) => None,
271272
}
272273
}

crates/rsonpath-lib/src/query/automaton.rs

+6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ pub struct Automaton<'q> {
2121
/// Represent the distinct methods of moving on a match between states.
2222
#[derive(Debug, Copy, PartialEq, Clone, Eq)]
2323
pub enum TransitionLabel<'q> {
24+
/// Wraps a textual field [`Label`] in a JSON object.
2425
ObjectMember(&'q Label),
26+
/// Wraps an array index [`NonNegativeArrayIndex`] in a JSON object.
2527
ArrayIndex(NonNegativeArrayIndex),
2628
}
2729

@@ -38,6 +40,7 @@ impl<'q> TransitionLabel<'q> {
3840
}
3941
}
4042

43+
///Return the textual [`Label`] being wrapped if so. Returns [`None`] otherwise.
4144
#[must_use]
4245
#[inline(always)]
4346
pub fn get_label(&self) -> Option<&Label> {
@@ -47,6 +50,7 @@ impl<'q> TransitionLabel<'q> {
4750
}
4851
}
4952

53+
/// Consumes the [`TransitionLabel`] and gives the wrapped [`Label`], if so. Returns [`None`] otherwise.
5054
#[must_use]
5155
#[inline(always)]
5256
pub fn get_label_owned(self) -> Option<&'q Label> {
@@ -56,12 +60,14 @@ impl<'q> TransitionLabel<'q> {
5660
}
5761
}
5862

63+
/// Wraps a [`Label`] in a [`TransitionLabel`].
5964
#[must_use]
6065
#[inline(always)]
6166
pub fn new_object_member(label: &'q Label) -> Self {
6267
TransitionLabel::ObjectMember(label)
6368
}
6469

70+
/// Wraps a [`NonNegativeArrayIndex`] in a [`TransitionLabel`].
6571
#[must_use]
6672
#[inline(always)]
6773
pub fn new_array_index(label: NonNegativeArrayIndex) -> Self {

crates/rsonpath-lib/src/query/nonnegative_array_index.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ use std::fmt::{self, Display, Formatter};
55
///
66
/// Represents a specific location from the front of the list in a json array.
77
/// Provides the [IETF-conforming index value](https://www.rfc-editor.org/rfc/rfc7493.html#section-2). Values are \[0, (2^53)-1].
8+
/// # Examples
9+
///
10+
/// ```
11+
/// # use rsonpath_lib::query::NonNegativeArrayIndex;
12+
///
13+
/// let idx = NonNegativeArrayIndex::new(2);
14+
///
15+
/// assert_eq!(idx.get_index(), 2);
16+
/// ```
817
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
918
pub struct NonNegativeArrayIndex(u64);
1019

1120
/// The upper inclusive bound on index values.
12-
pub const ARRAY_INDEX_ULIMIT: u64 = (1 << 53) - 1;
21+
pub(crate) const ARRAY_INDEX_ULIMIT: u64 = (1 << 53) - 1;
1322
impl TryFrom<u64> for NonNegativeArrayIndex {
1423
type Error = ArrayIndexError;
1524

0 commit comments

Comments
 (0)