Skip to main content

everymap_providers_here/
ext.rs

1use async_trait::async_trait;
2use everymap_core::error::EveryMapResult;
3
4/// Extension trait for HERE-specific geocoder capabilities.
5///
6/// These methods are not part of the core `Geocoder` trait because they
7/// are HERE-specific. Import this trait to access them:
8///
9/// ```ignore
10/// use everymap_providers_here::HereGeocoderExt;
11/// let results = geocoder.discover(query, &options).await?;
12/// ```
13#[async_trait]
14pub trait HereGeocoderExt: Send + Sync {
15    /// Discover places/POIs matching a query.
16    async fn discover(
17        &self,
18        req: super::domain::search::DiscoverRequest,
19    ) -> EveryMapResult<super::domain::search::HereDiscoverResponse>;
20
21    /// Get autosuggest results for a partial query (type-ahead).
22    async fn autosuggest(
23        &self,
24        req: super::domain::search::AutosuggestRequest,
25    ) -> EveryMapResult<super::domain::search::HereAutosuggestResponse>;
26}
27
28/// Extension trait for HERE-specific traffic capabilities.
29#[async_trait]
30pub trait HereTrafficExt: Send + Sync {
31    /// Get detailed traffic flow data.
32    async fn get_flow(
33        &self,
34        location: everymap_core::types::Coordinate,
35        options: &super::domain::traffic::HereFlowOptions,
36    ) -> EveryMapResult<super::domain::traffic::HereFlowResponse>;
37
38    /// Get traffic incidents in an area.
39    async fn get_incidents(
40        &self,
41        options: &super::domain::traffic::HereIncidentsOptions,
42    ) -> EveryMapResult<super::domain::traffic::HereIncidentsResponse>;
43}
44
45/// Extension trait for HERE-specific positioning capabilities.
46#[async_trait]
47pub trait HerePositionerExt: Send + Sync {
48    /// Get a position estimate using WiFi/cell/Bluetooth observations.
49    async fn locate(
50        &self,
51        options: super::domain::positioning::HerePositioningOptions,
52    ) -> EveryMapResult<super::domain::positioning::PositioningResponse>;
53}
54
55/// Extension trait for HERE-specific tour planning capabilities.
56#[async_trait]
57pub trait HereTourPlannerExt: Send + Sync {
58    /// Solve a tour planning problem synchronously.
59    async fn solve(
60        &self,
61        problem: super::domain::tour::TourProblem,
62    ) -> EveryMapResult<super::domain::tour::TourSolution>;
63
64    /// Submit a tour planning problem for asynchronous solving.
65    async fn solve_async(
66        &self,
67        problem: super::domain::tour::TourProblem,
68    ) -> EveryMapResult<super::domain::tour::AsyncSubmissionResult>;
69
70    /// Get the status of an async tour planning job.
71    async fn get_async_status(
72        &self,
73        status_id: &str,
74    ) -> EveryMapResult<super::domain::tour::AsyncJobStatus>;
75
76    /// Get the solution for a completed async tour planning job.
77    async fn get_solution(
78        &self,
79        problem_id: &str,
80    ) -> EveryMapResult<super::domain::tour::TourSolution>;
81
82    /// Cancel an async tour planning job.
83    async fn cancel(
84        &self,
85        problem_id: &str,
86    ) -> EveryMapResult<super::domain::tour::CancellationStatus>;
87
88    /// Get the version of the tour planning API.
89    async fn version(&self) -> EveryMapResult<super::domain::tour::VersionResponse>;
90
91    /// Check the health of the tour planning API.
92    async fn health(&self) -> EveryMapResult<super::domain::tour::HealthResponse>;
93}
94
95/// Extension trait for HERE-specific attribute capabilities.
96///
97/// Provides typed access to the Map Attributes API v8 layers.
98#[async_trait]
99pub trait HereAttributeExt: Send + Sync {
100    /// Get road attributes for a bounding box.
101    async fn get_road_attributes(
102        &self,
103        bbox: &str,
104        includes: Option<Vec<String>>,
105    ) -> EveryMapResult<super::domain::attributes::HereRoadAttributesResponse>;
106
107    /// Get segment (topology) attributes for a bounding box.
108    async fn get_segment_attributes(
109        &self,
110        bbox: &str,
111        includes: Option<Vec<String>>,
112    ) -> EveryMapResult<super::domain::attributes::HereSegmentAttributesResponse>;
113
114    /// Get administrative area attributes for a bounding box.
115    async fn get_admin_areas(
116        &self,
117        bbox: &str,
118    ) -> EveryMapResult<super::domain::attributes::HereAdminAreasResponse>;
119
120    /// Get building attributes for a bounding box.
121    async fn get_buildings(
122        &self,
123        bbox: &str,
124    ) -> EveryMapResult<super::domain::attributes::HereBuildingsResponse>;
125
126    /// Get landmark attributes for a bounding box.
127    async fn get_landmarks(
128        &self,
129        bbox: &str,
130    ) -> EveryMapResult<super::domain::attributes::HereLandmarksResponse>;
131
132    /// Get road attributes by specific feature IDs.
133    async fn get_road_attributes_by_ids(
134        &self,
135        ids: &[String],
136    ) -> EveryMapResult<super::domain::attributes::HereRoadAttributesResponse>;
137
138    /// Get speed limits for a bounding area (convenience method).
139    async fn get_speed_limits(
140        &self,
141        bbox: &str,
142    ) -> EveryMapResult<super::domain::attributes::HereRoadAttributesResponse>;
143}
144
145// --- Extension trait implementations ---
146
147#[async_trait]
148impl HereGeocoderExt for super::domain::search::HereGeocoder {
149    async fn discover(
150        &self,
151        req: super::domain::search::DiscoverRequest,
152    ) -> EveryMapResult<super::domain::search::HereDiscoverResponse> {
153        self.discover(req).await
154    }
155
156    async fn autosuggest(
157        &self,
158        req: super::domain::search::AutosuggestRequest,
159    ) -> EveryMapResult<super::domain::search::HereAutosuggestResponse> {
160        self.autosuggest(req).await
161    }
162}
163
164#[async_trait]
165impl HereTrafficExt for super::domain::traffic::HereTraffic {
166    async fn get_flow(
167        &self,
168        location: everymap_core::types::Coordinate,
169        options: &super::domain::traffic::HereFlowOptions,
170    ) -> EveryMapResult<super::domain::traffic::HereFlowResponse> {
171        self.get_flow(location, options).await
172    }
173
174    async fn get_incidents(
175        &self,
176        options: &super::domain::traffic::HereIncidentsOptions,
177    ) -> EveryMapResult<super::domain::traffic::HereIncidentsResponse> {
178        self.get_incidents(options).await
179    }
180}
181
182#[async_trait]
183impl HerePositionerExt for super::domain::positioning::HerePositioner {
184    async fn locate(
185        &self,
186        options: super::domain::positioning::HerePositioningOptions,
187    ) -> EveryMapResult<super::domain::positioning::PositioningResponse> {
188        self.locate(options).await
189    }
190}
191
192#[async_trait]
193impl HereTourPlannerExt for super::domain::tour::HereTourPlanner {
194    async fn solve(
195        &self,
196        problem: super::domain::tour::TourProblem,
197    ) -> EveryMapResult<super::domain::tour::TourSolution> {
198        self.solve(problem).await
199    }
200
201    async fn solve_async(
202        &self,
203        problem: super::domain::tour::TourProblem,
204    ) -> EveryMapResult<super::domain::tour::AsyncSubmissionResult> {
205        self.solve_async(problem).await
206    }
207
208    async fn get_async_status(
209        &self,
210        status_id: &str,
211    ) -> EveryMapResult<super::domain::tour::AsyncJobStatus> {
212        self.get_async_status(status_id).await
213    }
214
215    async fn get_solution(
216        &self,
217        problem_id: &str,
218    ) -> EveryMapResult<super::domain::tour::TourSolution> {
219        self.get_solution(problem_id).await
220    }
221
222    async fn cancel(
223        &self,
224        problem_id: &str,
225    ) -> EveryMapResult<super::domain::tour::CancellationStatus> {
226        self.cancel(problem_id).await
227    }
228
229    async fn version(&self) -> EveryMapResult<super::domain::tour::VersionResponse> {
230        self.version().await
231    }
232
233    async fn health(&self) -> EveryMapResult<super::domain::tour::HealthResponse> {
234        self.health().await
235    }
236}
237
238#[async_trait]
239impl HereAttributeExt for super::domain::attributes::HereAttributeProvider {
240    async fn get_road_attributes(
241        &self,
242        bbox: &str,
243        includes: Option<Vec<String>>,
244    ) -> EveryMapResult<super::domain::attributes::HereRoadAttributesResponse> {
245        self.get_road_attributes(bbox, includes).await
246    }
247
248    async fn get_segment_attributes(
249        &self,
250        bbox: &str,
251        includes: Option<Vec<String>>,
252    ) -> EveryMapResult<super::domain::attributes::HereSegmentAttributesResponse> {
253        self.get_segment_attributes(bbox, includes).await
254    }
255
256    async fn get_admin_areas(
257        &self,
258        bbox: &str,
259    ) -> EveryMapResult<super::domain::attributes::HereAdminAreasResponse> {
260        self.get_admin_areas(bbox).await
261    }
262
263    async fn get_buildings(
264        &self,
265        bbox: &str,
266    ) -> EveryMapResult<super::domain::attributes::HereBuildingsResponse> {
267        self.get_buildings(bbox).await
268    }
269
270    async fn get_landmarks(
271        &self,
272        bbox: &str,
273    ) -> EveryMapResult<super::domain::attributes::HereLandmarksResponse> {
274        self.get_landmarks(bbox).await
275    }
276
277    async fn get_road_attributes_by_ids(
278        &self,
279        ids: &[String],
280    ) -> EveryMapResult<super::domain::attributes::HereRoadAttributesResponse> {
281        self.get_road_attributes_by_ids(ids).await
282    }
283
284    async fn get_speed_limits(
285        &self,
286        bbox: &str,
287    ) -> EveryMapResult<super::domain::attributes::HereRoadAttributesResponse> {
288        self.get_speed_limits(bbox).await
289    }
290}