use facet_core::Shape;
use crate::PathStep;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum PathAccessError {
RootShapeMismatch {
expected: &'static Shape,
actual: &'static Shape,
},
WrongStepKind {
step: PathStep,
step_index: usize,
shape: &'static Shape,
},
IndexOutOfBounds {
step: PathStep,
step_index: usize,
shape: &'static Shape,
index: usize,
bound: usize,
},
VariantMismatch {
step_index: usize,
shape: &'static Shape,
expected_variant: usize,
actual_variant: usize,
},
MissingTarget {
step: PathStep,
step_index: usize,
shape: &'static Shape,
},
OptionIsNone {
step_index: usize,
shape: &'static Shape,
},
}
impl core::fmt::Display for PathAccessError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
PathAccessError::RootShapeMismatch { expected, actual } => {
write!(
f,
"root shape mismatch: path expects {expected}, value is {actual}"
)
}
PathAccessError::WrongStepKind {
step,
step_index,
shape,
} => {
write!(
f,
"step {step_index} ({step:?}) does not apply to shape {shape}"
)
}
PathAccessError::IndexOutOfBounds {
step,
step_index,
shape,
index,
bound,
} => {
write!(
f,
"step {step_index} ({step:?}): index {index} out of bounds for {shape} (has {bound})"
)
}
PathAccessError::VariantMismatch {
step_index,
shape,
expected_variant,
actual_variant,
} => {
write!(
f,
"step {step_index}: variant mismatch on {shape}: path expects variant {expected_variant}, value has variant {actual_variant}"
)
}
PathAccessError::MissingTarget {
step,
step_index,
shape,
} => {
write!(
f,
"step {step_index} ({step:?}): no target available for {shape}"
)
}
PathAccessError::OptionIsNone { step_index, shape } => {
write!(
f,
"step {step_index}: option {shape} is None, cannot navigate into Some"
)
}
}
}
}
impl core::error::Error for PathAccessError {}