france_api_adresse/
types.rs1use std::fmt;
2
3use serde::Deserialize;
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7 #[error("HTTP error: unable to access the API")]
8 HttpError(#[from] reqwest::Error),
9 #[error("Error extracting response: {0}")]
10 GetTextError(String),
11 #[error("Error unmarshalling JSON response: {0}")]
12 UnmarshalJsonError(String),
13 #[error("API error: {code} - {message}")]
14 ApiError {
15 code: u16,
16 message: String,
17 detail: Option<Vec<String>>,
18 },
19}
20
21#[derive(Deserialize, Debug)]
23pub struct AddressResult {
24 pub r#type: String,
25 pub features: Vec<FeatureResult>,
26}
27
28#[derive(Deserialize, Debug)]
30pub struct FeatureResult {
31 pub r#type: String,
32 pub geometry: GeometryResult,
33 pub properties: PropertiesResult,
34}
35
36#[derive(Deserialize, Debug)]
38pub struct GeometryResult {
39 pub r#type: String,
40 pub coordinates: Coordinates,
41}
42
43#[derive(Deserialize, Debug)]
45pub struct Coordinates {
46 #[serde(rename = "0")]
47 pub lon: f64,
48
49 #[serde(rename = "1")]
50 pub lat: f64,
51}
52
53#[derive(Deserialize, Debug)]
55pub struct PropertiesResult {
56 pub id: String,
57
58 pub score: f64,
59 pub label: String,
61
62 pub x: f64,
64 pub y: f64,
66
67 pub importance: f64,
68
69 pub r#type: String,
71
72 pub name: String,
74
75 pub housenumber: Option<String>,
76 pub street: Option<String>,
77 pub postcode: String,
78 pub citycode: String,
79
80 pub context: String,
81}
82
83#[derive(Debug, Clone)]
85pub enum FilterType {
86 HouseNumber,
87 Street,
88 Locality,
89 Municipality,
90}
91impl fmt::Display for FilterType {
92 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93 match self {
94 FilterType::HouseNumber => write!(f, "housenumber"),
95 FilterType::Street => write!(f, "street"),
96 FilterType::Locality => write!(f, "locality"),
97 FilterType::Municipality => write!(f, "municipality"),
98 }
99 }
100}
101#[derive(Debug, serde::Deserialize)]
102pub(crate) struct ApiErrorResponse {
103 pub code: u16,
104 pub message: String,
105 pub detail: Option<Vec<String>>,
106}