essential_types/predicate/header/
error.rsuse std::fmt::Display;
pub type DecodeResult<T> = core::result::Result<T, DecodeError>;
#[derive(Debug)]
pub enum PredicateError {
StateReadTooLarge(usize),
ConstraintTooLarge(usize),
TooManyStateReads(usize),
TooManyConstraints(usize),
PredicateTooLarge(usize),
}
#[derive(Debug)]
pub enum DecodeError {
MissingNumStateReads,
MissingNumConstraints,
MissingNestedLen,
Overflow,
IncorrectBodyLength,
BufferTooSmall,
PredicateError(PredicateError),
}
impl std::error::Error for PredicateError {}
impl std::error::Error for DecodeError {}
impl Display for DecodeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DecodeError::MissingNumStateReads => {
write!(
f,
"missing number of state reads when decoding predicate header"
)
}
DecodeError::MissingNumConstraints => {
write!(
f,
"missing number of constraints when decoding predicate header"
)
}
DecodeError::MissingNestedLen => {
write!(f, "missing nested length when decoding predicate header")
}
DecodeError::Overflow => {
write!(f, "overflow when decoding predicate")
}
DecodeError::IncorrectBodyLength => {
write!(f, "incorrect body length when decoding predicate")
}
DecodeError::BufferTooSmall => {
write!(f, "buffer too small when decoding predicate header")
}
DecodeError::PredicateError(e) => {
write!(f, "predicate error: {}", e)
}
}
}
}
impl Display for PredicateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PredicateError::StateReadTooLarge(s) => {
write!(f, "state read too large when encoding predicate: {}", s)
}
PredicateError::ConstraintTooLarge(s) => {
write!(f, "constraint too large when encoding predicate: {}", s)
}
PredicateError::TooManyStateReads(s) => {
write!(f, "too many state reads when encoding predicate: {}", s)
}
PredicateError::TooManyConstraints(s) => {
write!(f, "too many constraints when encoding predicate: {}", s)
}
PredicateError::PredicateTooLarge(s) => {
write!(f, "predicate too large when encoding predicate: {}", s)
}
}
}
}
impl From<PredicateError> for DecodeError {
fn from(e: PredicateError) -> Self {
DecodeError::PredicateError(e)
}
}