Debian Codegraph @

src/api/mod.rs

raw symbols SCIP
1 mod journeys;
2 mod locations;
3 mod refresh_journey;
4 mod station_board;
5
6 pub use journeys::*;
7 pub use locations::*;
8 pub use refresh_journey::*;
9 pub use station_board::*;
10
11 use crate::{Journey, Place, Requester};
12 use async_trait::async_trait;
13
14 /// The core type definition specifying what a provider needs to do.
15 ///
16 /// To implement the required methods, a provider usually queries an external but public API.
17 #[cfg_attr(feature = "rt-multi-thread", async_trait)]
18 #[cfg_attr(not(feature = "rt-multi-thread"), async_trait(?Send))]
19 pub trait Provider<R: Requester> {
20 type Error: std::error::Error;
21
22 /// Query a list of journeys.
23 ///
24 /// Be careful about timezones!
25 /// The types given to you are annotated with an arbitrary timezone, your public API may only understand one specific timezone though.
26 /// Ensure you correctly convert the given timezone to a timezone you require.
27 /// For returning a date and time, you may choose an arbitrary timezone.
28 async fn journeys(
29 &self,
30 from: Place,
31 to: Place,
32 opts: JourneysOptions,
33 ) -> Result<JourneysResponse, crate::Error<R::Error, Self::Error>>;
34
35 /// Autocomplete a location.
36 ///
37 /// This takes a query string and should return a list of locations which match the given string.
38 async fn locations(
39 &self,
40 opts: LocationsOptions,
41 ) -> Result<LocationsResponse, crate::Error<R::Error, Self::Error>>;
42
43 /// Query a list of arrivals/departures from a given station.
44 async fn station_board(
45 &self,
46 place: Place,
47 kind: StationBoardKind,
48 opts: StationBoardOptions,
49 ) -> Result<StationBoardResponse, crate::Error<R::Error, Self::Error>>;
50
51 /// Refresh a journey.
52 ///
53 /// This takes a previously queried journey and refreshes real-time data.
54 /// A naive implementation may call [`Provider::journeys`] again and return the matching journey, this is a valid strategy if there is no API for refreshing a journey.
55 async fn refresh_journey(
56 &self,
57 journey: &Journey,
58 opts: RefreshJourneyOptions,
59 ) -> Result<RefreshJourneyResponse, crate::Error<R::Error, Self::Error>>;
60 }