what3words_api/models/
gridsection.rs1use std::fmt;
2
3use serde::Deserialize;
4
5use crate::Coordinates;
6
7use super::feature::Feature;
8
9pub trait FormattedGridSection {
10 fn format() -> &'static str;
11}
12
13#[derive(Debug, Deserialize)]
14pub struct Line {
15 pub start: Coordinates,
16 pub end: Coordinates,
17}
18
19#[derive(Debug, Deserialize)]
20pub struct GridSection {
21 pub lines: Vec<Line>,
22}
23
24impl FormattedGridSection for GridSection {
25 fn format() -> &'static str {
26 "json"
27 }
28}
29
30#[derive(Debug, Deserialize)]
31pub struct GridSectionGeoJson {
32 pub features: Vec<Feature<Geometry>>,
33 #[serde(rename = "type")]
34 pub kind: String,
35}
36
37impl FormattedGridSection for GridSectionGeoJson {
38 fn format() -> &'static str {
39 "geojson"
40 }
41}
42
43#[derive(Debug, Deserialize)]
44pub struct Geometry {
45 pub coordinates: Vec<Vec<Vec<f32>>>,
46 #[serde(rename = "type")]
47 pub kind: String,
48}
49
50#[derive(Debug, Clone)]
51pub struct BoundingBox {
52 southwest: Coordinates,
53 northeast: Coordinates,
54}
55
56impl fmt::Display for BoundingBox {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58 write!(
59 f,
60 "{},{},{},{}",
61 self.southwest.lat, self.southwest.lng, self.northeast.lat, self.northeast.lng
62 )
63 }
64}
65
66impl BoundingBox {
67 pub fn new(sw_lat: f64, sw_lng: f64, ne_lat: f64, ne_lng: f64) -> Self {
68 Self {
69 southwest: Coordinates {
70 lat: sw_lat,
71 lng: sw_lng,
72 },
73 northeast: Coordinates {
74 lat: ne_lat,
75 lng: ne_lng,
76 },
77 }
78 }
79}