1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Error types for space operations.
use murk_core::Coord;
use std::fmt;
/// Errors arising from space construction or spatial queries.
#[derive(Debug, Clone)]
pub enum SpaceError {
/// A coordinate is outside the bounds of the space.
CoordOutOfBounds {
/// The offending coordinate.
coord: Coord,
/// Human-readable description of the valid range.
bounds: String,
},
/// A region specification is invalid for this space.
InvalidRegion {
/// What went wrong.
reason: String,
},
/// Attempted to construct a space with zero cells.
EmptySpace,
/// A dimension exceeds the representable coordinate range.
DimensionTooLarge {
/// Which dimension is too large (e.g. "len", "rows", "cols").
name: &'static str,
/// The value that was provided.
value: u32,
/// The maximum allowed value.
max: u32,
},
/// A space composition is invalid (e.g. empty component list, overflow).
InvalidComposition {
/// What went wrong.
reason: String,
},
}
impl fmt::Display for SpaceError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::CoordOutOfBounds { coord, bounds } => {
write!(f, "coordinate {coord:?} out of bounds: {bounds}")
}
Self::InvalidRegion { reason } => {
write!(f, "invalid region: {reason}")
}
Self::EmptySpace => write!(f, "space must have at least one cell"),
Self::DimensionTooLarge { name, value, max } => {
write!(f, "{name} ({value}) exceeds maximum ({max})")
}
Self::InvalidComposition { reason } => {
write!(f, "invalid composition: {reason}")
}
}
}
}
impl std::error::Error for SpaceError {}