1pub mod prelude;
21
22pub use jetro_core::{
24 Compiler, Engine, EvalError, Expr, Graph, Jetro, JetroSchema, Method, MethodRegistry,
25 ParseError, Program, VM,
26};
27
28pub use jetro_core::ast;
30pub use jetro_core::eval;
31pub use jetro_core::parser;
32pub use jetro_core::vm;
33
34#[cfg(feature = "macros")]
35pub use jetro_macros::{jetro, JetroSchema};
36
37use serde_json::Value;
38use std::sync::Arc;
39
40#[derive(Debug)]
42pub enum Error {
43 Parse(ParseError),
44 Eval(EvalError),
45}
46
47pub type Result<T> = std::result::Result<T, Error>;
48
49impl std::fmt::Display for Error {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 match self {
52 Error::Parse(e) => write!(f, "{}", e),
53 Error::Eval(e) => write!(f, "{}", e),
54 }
55 }
56}
57impl std::error::Error for Error {
58 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
59 match self {
60 Error::Parse(e) => Some(e),
61 Error::Eval(_) => None,
62 }
63 }
64}
65
66impl From<ParseError> for Error { fn from(e: ParseError) -> Self { Error::Parse(e) } }
67impl From<EvalError> for Error { fn from(e: EvalError) -> Self { Error::Eval(e) } }
68
69impl From<jetro_core::Error> for Error {
70 fn from(e: jetro_core::Error) -> Self {
71 match e {
72 jetro_core::Error::Parse(p) => Error::Parse(p),
73 jetro_core::Error::Eval(v) => Error::Eval(v),
74 }
75 }
76}
77
78pub fn query(expr: &str, doc: &Value) -> Result<Value> {
80 Ok(jetro_core::query(expr, doc)?)
81}
82
83pub fn query_with(expr: &str, doc: &Value, registry: Arc<MethodRegistry>) -> Result<Value> {
85 Ok(jetro_core::query_with(expr, doc, registry)?)
86}