overpass_lib/query/
overpassql.rs1use std::fmt::{Display, Formatter, Write, Result as FResult, Error as FmtError};
2use crate::Namer;
3
4#[derive(Debug, Clone)]
6pub enum OverpassQLError {
7 Format,
9 CircularReference,
11}
12
13impl Display for OverpassQLError {
14 fn fmt(&self, f: &mut Formatter<'_>) -> FResult {
15 match self {
16 Self::Format => write!(f, "Format"),
17 Self::CircularReference => write!(f, "Circular reference"),
18 }
19 }
20}
21
22impl std::error::Error for OverpassQLError {}
23
24impl From<FmtError> for OverpassQLError {
25 fn from(_: FmtError) -> Self {
26 Self::Format
27 }
28}
29impl Into<FmtError> for OverpassQLError {
30 fn into(self) -> FmtError {
31 FmtError
32 }
33}
34
35pub trait OverpassQL {
37 fn fmt_oql(&self, f: &mut impl Write) -> Result<(), OverpassQLError>;
39
40 fn to_oql(&self) -> String {
42 let mut buf = String::new();
43
44 OverpassQL::fmt_oql(self, &mut buf)
46 .expect("an OverpassQL implementation returned an error unexpectedly");
47 buf
48 }
49}
50
51
52pub(crate) trait OverpassQLNamed<'a> {
53 #[allow(unused_variables)]
54 fn fmt_oql_named<'b, 'c>(&'b self, f: &mut impl Write, namer: &mut Namer<'a, 'c>)
55 -> Result<(), OverpassQLError>
56 where 'b: 'c;
57}