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
60
61
62
63
64
65
66
67
68
69
//! Geometry deserialization from [`geo_traits`] sources.
//!
//! The central trait is [`DeserializeGeometry`], which converts a
//! [`GeometryTrait`](geo_traits::GeometryTrait) value into a concrete Rust type.
//! When the `geo` feature is enabled, implementations are provided for the
//! common [`geo_types`] geometry types.
/// Converts a [`GeometryTrait`](geo_traits::GeometryTrait) value into `Self`.
///
/// Implement this trait for your own geometry types so they can be
/// deserialized from any GIS source that exposes geometries through
/// [`geo_traits`].
///
/// # Errors
///
/// Returns [`GeometryTypeMismatch`] if the source geometry cannot be
/// interpreted as the target type.
///
/// # Example
///
/// ```
/// use geoserde::de::{DeserializeGeometry, GeometryTypeMismatch};
///
/// struct Xy { x: f64, y: f64 }
///
/// impl DeserializeGeometry for Xy {
/// fn deserialize_geometry<T: geo_traits::GeometryTrait<T = f64>>(
/// source: T,
/// ) -> Result<Self, GeometryTypeMismatch> {
/// use geo_traits::{CoordTrait, GeometryType, PointTrait};
/// match source.as_type() {
/// GeometryType::Point(p) => {
/// let c = p.coord().ok_or(GeometryTypeMismatch::new("Point"))?;
/// Ok(Xy { x: c.x(), y: c.y() })
/// }
/// _ => Err(GeometryTypeMismatch::new("Point")),
/// }
/// }
/// }
/// ```
/// Error returned when a geometry's type does not match the expected target.