1use std::{
2 collections::HashMap,
3 fmt::{Display, Formatter, Result as FResult},
4};
5use serde::Deserialize;
6use crate::{Element, OverpassQLError, Query};
7
8mod server;
9pub use server::*;
10
11#[derive(Debug)]
13pub enum OverpassError {
14 Query(OverpassQLError),
16 Request(reqwest::Error),
18 Parse(serde_json::Error),
20 Other(String),
22}
23impl Display for OverpassError {
24 fn fmt(&self, f: &mut Formatter<'_>) -> FResult {
25 match self {
26 Self::Query(e) => write!(f, "{e}"),
27 Self::Request(e) => write!(f, "{e}"),
28 Self::Parse(e) => write!(f, "Deserialization error: {e}"),
29 Self::Other(e) => write!(f, "Error from API provider: {e}"),
30 }
31 }
32}
33impl std::error::Error for OverpassError {}
34
35#[derive(Debug, Clone, PartialEq, Deserialize)]
37pub struct OverpassResult {
38 pub elements: Vec<Element>,
40
41 #[serde(flatten)]
43 pub other_fields: HashMap<String, serde_json::Value>,
44}
45
46pub trait Overpass {
48 fn evaluate(&self, query: &Query<'_>) -> impl std::future::Future<Output = Result<OverpassResult, OverpassError>> + Send;
51}