Skip to main content

IndexedDocument

Struct IndexedDocument 

Source
pub struct IndexedDocument<'a> { /* private fields */ }
Expand description

A JSON buffer plus structural / array / object indexes for path-accelerated reads.

Implementations§

Source§

impl<'a> IndexedDocument<'a>

Source

pub fn empty(json: &'a [u8]) -> Self

Empty index over json (no side-tables yet).

Source

pub fn build(json: &'a [u8], array_paths: &[&str]) -> Result<Self, Error>

Build array side-tables for each path (lenient path parse).

use jshift::IndexedDocument;

let json = br#"{"products":[{"id":1},{"id":2},{"id":3}]}"#;
let doc = IndexedDocument::build(json, &["products"]).unwrap();
assert_eq!(doc.array_len(&jshift::parse_path("products")).unwrap(), 3);
assert_eq!(
    doc.find(&jshift::parse_path("products[2].id")).unwrap(),
    b"3"
);
Source

pub fn build_paths( json: &'a [u8], array_paths: &[&[PathSegment<'_>]], ) -> Result<Self, Error>

Build array side-tables from segment slices.

Source

pub fn build_structural(json: &'a [u8]) -> Result<Self, Error>

Build Stage-1 structural index only (no array/object tables yet).

Source

pub fn build_full( json: &'a [u8], array_paths: &[&str], object_paths: &[&str], ) -> Result<Self, Error>

Full convenience: structural + arrays + objects.

Source

pub fn as_bytes(&self) -> &'a [u8] ⓘ

Source

pub fn index_structural(&mut self) -> Result<(), Error>

Build or replace the document-wide Stage-1 structural list.

Source

pub fn structural(&self) -> Option<&StructuralIndex>

Source

pub fn index_array(&mut self, path: &[PathSegment<'_>]) -> Result<(), Error>

Index the array at path.

Source

pub fn index_array_str(&mut self, path: &str) -> Result<(), Error>

Source

pub fn index_for_plan(&mut self, plan: &ProjectPlan) -> Result<(), Error>

Index every array path a crate::ProjectPlan will walk (idempotent).

Builds Stage-1 structurals when missing (helps large-array table builds), then array side-tables for each path from crate::ProjectPlan::array_paths_for_index. Already-indexed paths are left unchanged.

use jshift::{IndexedDocument, ProjectPlan, project_indexed};

let json = br#"{"products":[{"id":1},{"id":2},{"id":3}]}"#;
let plan = ProjectPlan::from_paths(&["products[2].id"]).unwrap();
let mut doc = IndexedDocument::empty(json);
doc.index_for_plan(&plan).unwrap();
assert_eq!(project_indexed(&doc, &plan).unwrap(), br#"{"products":{"id":3}}"#);
Source

pub fn index_object(&mut self, path: &[PathSegment<'_>]) -> Result<(), Error>

Index all keys of the object at path (value must be {...}).

Source

pub fn index_object_str(&mut self, path: &str) -> Result<(), Error>

Source

pub fn array_len(&self, path: &[PathSegment<'_>]) -> Option<usize>

Source

pub fn array_index(&self, path: &[PathSegment<'_>]) -> Option<&ArrayIndex>

Source

pub fn object_index(&self, path: &[PathSegment<'_>]) -> Option<&ObjectKeyIndex>

Source

pub fn array_index_at_open(&self, open: usize) -> Option<&ArrayIndex>

Look up an array side-table by the absolute offset of its opening [.

Used by the projector to jump elements in O(1) when the array was indexed (path-based) and emit visits the same on-wire span.

Source

pub fn object_index_at_open(&self, open: usize) -> Option<&ObjectKeyIndex>

Look up an object key map by the absolute offset of its opening {.

Source

pub fn find(&self, path: &[PathSegment<'_>]) -> Result<&'a [u8], Error>

Find using array / object indexes when applicable; else normal path scan.

Source

pub fn find_offsets( &self, path: &[PathSegment<'_>], ) -> Result<(usize, usize), Error>

Source

pub fn for_each_element<F>( &self, array_path: &[PathSegment<'_>], f: F, ) -> Result<(), Error>
where F: FnMut(usize, &'a [u8]) -> Result<(), Error>,

Source

pub fn for_each_element_str<F>( &self, array_path: &str, f: F, ) -> Result<(), Error>
where F: FnMut(usize, &'a [u8]) -> Result<(), Error>,

Source

pub fn indexed_array_count(&self) -> usize

Source

pub fn indexed_object_count(&self) -> usize

Trait Implementations§

Source§

impl<'a> Clone for IndexedDocument<'a>

Source§

fn clone(&self) -> IndexedDocument<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for IndexedDocument<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for IndexedDocument<'a>

§

impl<'a> RefUnwindSafe for IndexedDocument<'a>

§

impl<'a> Send for IndexedDocument<'a>

§

impl<'a> Sync for IndexedDocument<'a>

§

impl<'a> Unpin for IndexedDocument<'a>

§

impl<'a> UnsafeUnpin for IndexedDocument<'a>

§

impl<'a> UnwindSafe for IndexedDocument<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.