use thiserror::Error;
use crate::BatchOutcome;
#[derive(Debug, Clone, Error, PartialEq, Eq)]
pub enum BatchExecutionError<E> {
#[error("batch task count shortfall: expected {expected}, actual {actual}")]
CountShortfall {
expected: usize,
actual: usize,
outcome: BatchOutcome<E>,
},
#[error(
"batch task count exceeded: expected {expected}, observed at least {observed_at_least}"
)]
CountExceeded {
expected: usize,
observed_at_least: usize,
outcome: BatchOutcome<E>,
},
}
impl<E> BatchExecutionError<E> {
#[inline]
pub const fn outcome(&self) -> &BatchOutcome<E> {
match self {
Self::CountShortfall { outcome, .. } | Self::CountExceeded { outcome, .. } => outcome,
}
}
#[inline]
pub fn into_outcome(self) -> BatchOutcome<E> {
match self {
Self::CountShortfall { outcome, .. } | Self::CountExceeded { outcome, .. } => outcome,
}
}
#[inline]
pub const fn is_count_shortfall(&self) -> bool {
matches!(self, Self::CountShortfall { .. })
}
#[inline]
pub const fn is_count_exceeded(&self) -> bool {
matches!(self, Self::CountExceeded { .. })
}
}