postgis/
types.rs

1//
2// Copyright (c) Pirmin Kalberer. All rights reserved.
3//
4
5pub trait Point: Send + Sync {
6    fn x(&self) -> f64;
7    fn y(&self) -> f64;
8    fn opt_z(&self) -> Option<f64> {
9        None
10    }
11    fn opt_m(&self) -> Option<f64> {
12        None
13    }
14}
15
16pub trait LineString<'a>: Send + Sync {
17    type ItemType: 'a + Point;
18    type Iter: Iterator<Item = &'a Self::ItemType>;
19    fn points(&'a self) -> Self::Iter;
20}
21
22pub trait Polygon<'a>: Send + Sync {
23    type ItemType: 'a + LineString<'a>;
24    type Iter: Iterator<Item = &'a Self::ItemType>;
25    fn rings(&'a self) -> Self::Iter;
26}
27
28pub trait MultiPoint<'a>: Send + Sync {
29    type ItemType: 'a + Point;
30    type Iter: Iterator<Item = &'a Self::ItemType>;
31    fn points(&'a self) -> Self::Iter;
32}
33
34pub trait MultiLineString<'a>: Send + Sync {
35    type ItemType: 'a + LineString<'a>;
36    type Iter: Iterator<Item = &'a Self::ItemType>;
37    fn lines(&'a self) -> Self::Iter;
38}
39
40pub trait MultiPolygon<'a>: Send + Sync {
41    type ItemType: 'a + Polygon<'a>;
42    type Iter: Iterator<Item = &'a Self::ItemType>;
43    fn polygons(&'a self) -> Self::Iter;
44}
45
46pub trait Geometry<'a>: Send + Sync {
47    type Point: 'a + Point;
48    type LineString: 'a + LineString<'a>;
49    type Polygon: 'a + Polygon<'a>;
50    type MultiPoint: 'a + MultiPoint<'a>;
51    type MultiLineString: 'a + MultiLineString<'a>;
52    type MultiPolygon: 'a + MultiPolygon<'a>;
53    type GeometryCollection: 'a + GeometryCollection<'a>;
54    fn as_type(
55        &'a self,
56    ) -> GeometryType<
57        'a,
58        Self::Point,
59        Self::LineString,
60        Self::Polygon,
61        Self::MultiPoint,
62        Self::MultiLineString,
63        Self::MultiPolygon,
64        Self::GeometryCollection,
65    >;
66}
67
68pub enum GeometryType<'a, P, L, Y, MP, ML, MY, GC>
69where
70    P: 'a + Point,
71    L: 'a + LineString<'a>,
72    Y: 'a + Polygon<'a>,
73    MP: 'a + MultiPoint<'a>,
74    ML: 'a + MultiLineString<'a>,
75    MY: 'a + MultiPolygon<'a>,
76    GC: 'a + GeometryCollection<'a>,
77{
78    Point(&'a P),
79    LineString(&'a L),
80    Polygon(&'a Y),
81    MultiPoint(&'a MP),
82    MultiLineString(&'a ML),
83    MultiPolygon(&'a MY),
84    GeometryCollection(&'a GC),
85}
86
87pub trait GeometryCollection<'a> {
88    type ItemType: 'a;
89    type Iter: Iterator<Item = &'a Self::ItemType>;
90    fn geometries(&'a self) -> Self::Iter;
91}