use serde::Serialize;
use serde_json_borrow::Value;
use std::rc::Rc;
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct JSONPointer<'a> {
pub path: Vec<PathType>,
pub value: &'a Value<'a>,
}
impl std::fmt::Display for JSONPointer<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "path: {:#?}", self.path)?;
write!(f, "value: {:?}", self.value)
}
}
#[derive(Serialize, Hash, PartialEq, Eq, Debug, Clone)]
pub enum PathType {
Index(usize),
Field(Rc<String>),
}
impl std::fmt::Display for PathType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Index(i) => write!(f, "[{i}]"),
Self::Field(s) => write!(f, "{s}"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TransitionLabel {
Field(Rc<String>),
FieldWildcard,
Range(usize, usize),
RangeFrom(usize),
Other,
}
impl std::fmt::Display for TransitionLabel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Field(str) => write!(f, "Field({str})"),
Self::FieldWildcard => write!(f, "FieldWildcard"),
Self::Range(s, e) => write!(f, "Range({s}, {e})"),
Self::RangeFrom(s) => write!(f, "RangeFrom({s})"),
Self::Other => write!(f, "Other"),
}
}
}