pub struct Jetro { /* private fields */ }Expand description
Primary entry point for evaluating Jetro expressions.
Holds a JSON document and evaluates expressions against it. Internally
delegates to a thread-local VM so the compile cache and resolution
cache accumulate over the lifetime of the thread.
Implementations§
Source§impl Jetro
impl Jetro
pub fn new(document: Value) -> Self
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Result<Self, Error>
pub fn from_bytes(bytes: Vec<u8>) -> Result<Self, Error>
Parse JSON bytes and retain them alongside the parsed document.
Descendant queries ($..key) can then take the SIMD byte-scan path
instead of walking the tree.
Sourcepub fn from_slice(bytes: &[u8]) -> Result<Self, Error>
pub fn from_slice(bytes: &[u8]) -> Result<Self, Error>
Parse JSON from a slice, retaining a copy of the bytes.
Sourcepub fn collect<S: AsRef<str>>(&self, expr: S) -> Result<Value, EvalError>
pub fn collect<S: AsRef<str>>(&self, expr: S) -> Result<Value, EvalError>
Evaluate expr against the document. Routes through the thread-local
VM (compile + path caches); when the Jetro handle carries raw bytes
the VM executes on an env with raw_bytes set so Opcode::Descendant
can take the SIMD byte-scan fast path.
Sourcepub fn collect_val<S: AsRef<str>>(&self, expr: S) -> Result<JetroVal, EvalError>
pub fn collect_val<S: AsRef<str>>(&self, expr: S) -> Result<JetroVal, EvalError>
Evaluate expr and return the raw Val without converting to
serde_json::Value. For large structural results (e.g. group_by
on 20k+ items) this avoids an expensive materialisation that
otherwise dominates runtime. The returned Val supports cheap
Arc-clone and shares structure with the source document.
Prefer this over collect when the caller consumes the result
structurally (further queries, custom walk, re-evaluation) rather
than handing it to serde_json-aware code.