use thiserror::Error;
use super::batch_execution_result::BatchExecutionResult;
#[derive(Debug, Clone, Error, PartialEq, Eq)]
pub enum BatchExecutionError<E> {
#[error("batch task count shortfall: expected {expected}, actual {actual}")]
CountShortfall {
expected: usize,
actual: usize,
result: BatchExecutionResult<E>,
},
#[error(
"batch task count exceeded: expected {expected}, observed at least {observed_at_least}"
)]
CountExceeded {
expected: usize,
observed_at_least: usize,
result: BatchExecutionResult<E>,
},
}
impl<E> BatchExecutionError<E> {
#[inline]
pub const fn result(&self) -> &BatchExecutionResult<E> {
match self {
Self::CountShortfall { result, .. } | Self::CountExceeded { result, .. } => result,
}
}
#[inline]
pub fn into_result(self) -> BatchExecutionResult<E> {
match self {
Self::CountShortfall { result, .. } | Self::CountExceeded { result, .. } => result,
}
}
#[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 { .. })
}
}