use std::slice::GetDisjointMutError;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("the given index {index} is not mapped to any element")]
UnmappedIndex {
index: usize,
},
#[error("the given indices contain an overlapping pair of indices")]
OverlappingIndices,
#[error("the given index {index} is already mapped to an element")]
IndexAlreadyInUse {
index: usize,
},
#[error(
"The given index {actual_index} is not the next available insertion index {expected_index}"
)]
NotTheNextAvailableInsertionIndex {
expected_index: usize,
actual_index: usize,
},
}
impl From<GetDisjointMutError> for Error {
fn from(value: GetDisjointMutError) -> Self {
match value {
GetDisjointMutError::IndexOutOfBounds => {
unreachable!("We always want to report the index")
}
GetDisjointMutError::OverlappingIndices => Self::OverlappingIndices,
}
}
}
pub type Result<T> = std::result::Result<T, Error>;