geos/
error.rs

1use std::{self, fmt};
2
3#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone)]
4pub enum Error {
5    InvalidGeometry(String),
6    ImpossibleOperation(String),
7    GeosError(String),
8    GeosFunctionError(PredicateType, i32),
9    NoConstructionFromNullPtr(String),
10    ConversionError(String),
11    GenericError(String),
12    VoronoiError(String),
13    NormalizeError(String),
14}
15
16impl std::error::Error for Error {}
17
18impl fmt::Display for Error {
19    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20        match *self {
21            Error::InvalidGeometry(ref s) => write!(f, "Invalid geometry, {s}"),
22            Error::ImpossibleOperation(ref s) => write!(f, "Impossible operation, {s}"),
23            Error::GeosError(ref s) => write!(f, "error while calling libgeos while {s}"),
24            Error::GeosFunctionError(p, e) => write!(
25                f,
26                "error while calling libgeos method {p} (error number = {e})",
27            ),
28            Error::NoConstructionFromNullPtr(ref s) => write!(
29                f,
30                "impossible to build a geometry from a nullptr in \"{s}\"",
31            ),
32            Error::NormalizeError(ref s) => write!(f, "failed to normalize: {s}"),
33            Error::ConversionError(ref s) => write!(f, "impossible to convert geometry, {s}"),
34            Error::GenericError(ref s) => write!(f, "generic error: {s}"),
35            Error::VoronoiError(ref s) => write!(f, "voronoi error: {s}"),
36        }
37    }
38}
39
40pub type GResult<T> = std::result::Result<T, Error>;
41
42#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
43pub enum PredicateType {
44    Intersects,
45    Crosses,
46    Disjoint,
47    Touches,
48    Overlaps,
49    Within,
50    Equals,
51    EqualsExact,
52    Covers,
53    CoveredBy,
54    Contains,
55    IsRing,
56    IsEmpty,
57    IsSimple,
58    PreparedContains,
59    PreparedContainsProperly,
60    PreparedCoveredBy,
61    PreparedCovers,
62    PreparedCrosses,
63    PreparedDisjoint,
64    PreparedIntersects,
65    PreparedOverlaps,
66    PreparedTouches,
67    PreparedWithin,
68    Normalize,
69}
70
71impl std::fmt::Display for PredicateType {
72    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
73        write!(f, "{self:?}")
74    }
75}