general_stable_vec/
error.rs

1//! Errors and related types.
2
3use std::slice::GetDisjointMutError;
4
5use thiserror::Error;
6
7/// The error type.
8#[derive(Debug, Error)]
9pub enum Error {
10    /// The given index is not mapped to any element.
11    #[error("the given index {index} is not mapped to any element")]
12    UnmappedIndex {
13        /// The index.
14        index: usize,
15    },
16
17    /// The given indices contain an overlapping pair of indices.
18    #[error("the given indices contain an overlapping pair of indices")]
19    OverlappingIndices,
20
21    /// The given index is already mapped to an element.
22    #[error("the given index {index} is already mapped to an element")]
23    IndexAlreadyInUse {
24        /// The index.
25        index: usize,
26    },
27
28    /// The given index is not the next available insertion index.
29    #[error(
30        "The given index {actual_index} is not the next available insertion index {expected_index}"
31    )]
32    NotTheNextAvailableInsertionIndex {
33        /// The expected next available insertion index.
34        expected_index: usize,
35        /// The given invalid insertion index.
36        actual_index: usize,
37    },
38}
39
40impl From<GetDisjointMutError> for Error {
41    fn from(value: GetDisjointMutError) -> Self {
42        match value {
43            GetDisjointMutError::IndexOutOfBounds => {
44                unreachable!("We always want to report the index")
45            }
46            GetDisjointMutError::OverlappingIndices => Self::OverlappingIndices,
47        }
48    }
49}
50
51/// A shortcut result type using this crate's error type.
52pub type Result<T> = std::result::Result<T, Error>;