cell_map/
error.rs

1//! Defines the standard error type for errors related to [`CellMap`]s.
2//!
3//! [`CellMap`]: crate::CellMap
4
5use nalgebra::{Point2, Vector2};
6
7use crate::cell_map::Bounds;
8
9// ------------------------------------------------------------------------------------------------
10// ENUMS
11// ------------------------------------------------------------------------------------------------
12
13/// Standard error type for errors related to [`CellMap`]s.
14///
15/// [`CellMap`]: crate::CellMap
16#[derive(Debug, thiserror::Error)]
17pub enum Error {
18    /// Error returned when trying to construct a [`Windows`] slicer using a `semi_width` which
19    /// would create a window larger than the size of the map.
20    ///
21    /// [`Windows`]: crate::iterators::slicers::Windows
22    #[error("Can't create a Windows iterator since the window size ({0}) is larger than the map size ({1})")]
23    WindowLargerThanMap(Vector2<usize>, Vector2<usize>),
24
25    /// The given parent-frame position (name, first element) is outside the map.
26    #[error("Parent-frame position {0} ({1}) is outside the map")]
27    PositionOutsideMap(String, Point2<f64>),
28
29    /// The given index is outside the map.
30    #[error("The index {0} is outside the map")]
31    IndexOutsideMap(Point2<usize>),
32
33    /// Wrong number of layers, got (first) but expected (second)
34    #[error("Expected {0} layers but found {1}")]
35    WrongNumberOfLayers(usize, usize),
36
37    /// Wrong shape of layer, got (first) but expected (second)
38    #[error("Expected {0:?} cells in layer, but found {1:?}")]
39    LayerWrongShape((usize, usize), (usize, usize)),
40
41    /// Errors associated with `std::io` operations.
42    #[error("An IO error occured: {0}")]
43    IoError(std::io::Error),
44
45    /// Errors associated with `serde_json` operations.
46    #[cfg(feature = "json")]
47    #[error("Error in serde_json: {0}")]
48    JsonError(serde_json::Error),
49
50    /// Error when bounds are invalid, i.e. the minimum is larger than the maximum
51    #[error("The provided bounds are not valid: {0:?}")]
52    InvalidBounds(Bounds),
53}