Skip to main content

everymap_core/
unsupported.rs

1//! Macros for generating unsupported domain stub implementations.
2//!
3//! These macros eliminate boilerplate when a provider doesn't support a particular
4//! domain. Instead of manually writing trait implementations that return
5//! `EveryMapError::unsupported_domain`, use the appropriate macro.
6
7/// Generates an unsupported `IsolineProvider` stub implementation.
8#[macro_export]
9macro_rules! unsupported_isoline {
10    ($struct_name:ident, $provider:expr) => {
11        pub struct $struct_name;
12
13        #[async_trait::async_trait]
14        impl everymap_core::domains::isoline::IsolineProvider for $struct_name {
15            async fn get_isoline(
16                &self,
17                _center: &everymap_core::types::Coordinate,
18                _range: f64,
19                _options: &everymap_core::domains::isoline::IsolineOptions,
20            ) -> everymap_core::error::EveryMapResult<
21                everymap_core::domains::isoline::IsolineResponse,
22            > {
23                Err(everymap_core::error::EveryMapError::unsupported_domain(
24                    $provider, "isoline",
25                ))
26            }
27        }
28    };
29}
30
31/// Generates an unsupported `TrafficProvider` stub implementation.
32#[macro_export]
33macro_rules! unsupported_traffic {
34    ($struct_name:ident, $provider:expr) => {
35        pub struct $struct_name;
36
37        #[async_trait::async_trait]
38        impl everymap_core::domains::traffic::TrafficProvider for $struct_name {
39            async fn get_traffic(
40                &self,
41                _location: &everymap_core::types::Coordinate,
42                _options: &everymap_core::domains::traffic::TrafficOptions,
43            ) -> everymap_core::error::EveryMapResult<
44                everymap_core::domains::traffic::TrafficResponse,
45            > {
46                Err(everymap_core::error::EveryMapError::unsupported_domain(
47                    $provider, "traffic",
48                ))
49            }
50        }
51    };
52}
53
54/// Generates an unsupported `TourPlanner` stub implementation.
55#[macro_export]
56macro_rules! unsupported_tour {
57    ($struct_name:ident, $provider:expr) => {
58        pub struct $struct_name;
59
60        #[async_trait::async_trait]
61        impl everymap_core::domains::tour::TourPlanner for $struct_name {
62            async fn optimize_tour(
63                &self,
64                _stops: &[everymap_core::types::Coordinate],
65                _options: &everymap_core::domains::tour::TourOptions,
66            ) -> everymap_core::error::EveryMapResult<everymap_core::domains::tour::TourResponse>
67            {
68                Err(everymap_core::error::EveryMapError::unsupported_domain(
69                    $provider, "tour",
70                ))
71            }
72        }
73    };
74}
75
76/// Generates an unsupported `TileProvider` stub implementation.
77#[macro_export]
78macro_rules! unsupported_tile {
79    ($struct_name:ident, $provider:expr) => {
80        pub struct $struct_name;
81
82        #[async_trait::async_trait]
83        impl everymap_core::domains::tiling::TileProvider for $struct_name {
84            async fn get_tile(
85                &self,
86                _z: u32,
87                _x: u32,
88                _y: u32,
89                _options: &everymap_core::domains::tiling::TileOptions,
90            ) -> everymap_core::error::EveryMapResult<everymap_core::domains::tiling::TileResponse>
91            {
92                Err(everymap_core::error::EveryMapError::unsupported_domain(
93                    $provider, "tiling",
94                ))
95            }
96        }
97    };
98}
99
100/// Generates an unsupported `NetworkPositioner` stub implementation.
101#[macro_export]
102macro_rules! unsupported_positioner {
103    ($struct_name:ident, $provider:expr) => {
104        pub struct $struct_name;
105
106        #[async_trait::async_trait]
107        impl everymap_core::domains::positioning::NetworkPositioner for $struct_name {
108            async fn get_position(
109                &self,
110                _options: &everymap_core::domains::positioning::PositioningOptions,
111            ) -> everymap_core::error::EveryMapResult<
112                everymap_core::domains::positioning::PositioningResponse,
113            > {
114                Err(everymap_core::error::EveryMapError::unsupported_domain(
115                    $provider,
116                    "positioning",
117                ))
118            }
119        }
120    };
121}
122
123/// Generates an unsupported `AttributeProvider` stub implementation.
124#[macro_export]
125macro_rules! unsupported_attributes {
126    ($struct_name:ident, $provider:expr) => {
127        pub struct $struct_name;
128
129        #[async_trait::async_trait]
130        impl everymap_core::domains::attributes::AttributeProvider for $struct_name {
131            async fn get_attributes(
132                &self,
133                _options: &everymap_core::domains::attributes::AttributeOptions,
134            ) -> everymap_core::error::EveryMapResult<
135                everymap_core::domains::attributes::AttributeResponse,
136            > {
137                Err(everymap_core::error::EveryMapError::unsupported_domain(
138                    $provider,
139                    "attributes",
140                ))
141            }
142        }
143    };
144}
145
146/// Generates an unsupported `MapImageProvider` stub implementation.
147#[macro_export]
148macro_rules! unsupported_image {
149    ($struct_name:ident, $provider:expr) => {
150        pub struct $struct_name;
151
152        #[async_trait::async_trait]
153        impl everymap_core::domains::imaging::MapImageProvider for $struct_name {
154            async fn get_image(
155                &self,
156                _center: &everymap_core::types::Coordinate,
157                _zoom: u32,
158                _size: (u32, u32),
159                _options: &everymap_core::domains::imaging::ImageOptions,
160            ) -> everymap_core::error::EveryMapResult<everymap_core::domains::imaging::ImageResponse> {
161                Err(everymap_core::error::EveryMapError::unsupported_domain($provider, "imaging"))
162            }
163        }
164    };
165}