Debian Codegraph @

src/api/journeys.rs

raw symbols SCIP
1 use chrono::{DateTime, Duration};
2 use chrono_tz::Tz;
3
4 use crate::{Accessibility, Age, Journey, LoyaltyCard, Place, ProductsSelection, TariffClass};
5
6 #[derive(Debug, Clone)]
7 /// The options for [`Provider::journeys`](crate::Provider::journeys)
8 ///
9 /// A provider can also ignore some of the options if this is not supported by the API.
10 pub struct JourneysOptions {
11 /// Intermediate place to route with.
12 pub via: Vec<Place>,
13 /// Specify to route earlier than, from [`JourneysResponse::earlier_ref`].
14 pub earlier_than: Option<String>,
15 /// Specify to route earlierthan , from [`JourneysResponse::later_ref`].
16 pub later_than: Option<String>,
17 /// How many results to include.
18 pub results: u64,
19 /// Whether to include stopovers.
20 pub stopovers: bool,
21 /// Whether to include polylines.
22 #[cfg(feature = "polylines")]
23 pub polylines: bool,
24 /// Route in a bike-friendly way.
25 pub bike_friendly: bool,
26 /// Include tickets.
27 pub tickets: bool,
28 /// Allow to walk to the initial station.
29 pub start_with_walking: bool,
30 /// How accessible the journey must be.
31 pub accessibility: Accessibility,
32 /// How often it is allowed to transfer.
33 pub transfers: TransferOptions,
34 /// How long must the transfers be.
35 pub transfer_time: Duration,
36 /// When should the journey arrive, or earlier.
37 pub arrival: Option<DateTime<Tz>>,
38 /// When should the journey depart, or later.
39 pub departure: Option<DateTime<Tz>>,
40 /// What products to route with.
41 pub products: ProductsSelection,
42 /// What class to use.
43 pub tariff_class: TariffClass,
44 /// What language to query with.
45 pub language: Option<String>,
46 /// What loyalty cards does the passenger have.
47 pub loyalty_card: Option<LoyaltyCard>,
48 /// What age does the passenger have.
49 pub passenger_age: Option<Age>,
50 }
51
52 /// How often is a journey allowed to transfer.
53 #[derive(Debug, Clone, Default)]
54 pub enum TransferOptions {
55 /// Allow unlimited transfers.
56 #[default]
57 Unlimited,
58 /// Allow transfers only to a limited number.
59 Limited(u64),
60 }
61
62 impl Default for JourneysOptions {
63 fn default() -> Self {
64 Self {
65 via: Default::default(),
66 earlier_than: Default::default(),
67 later_than: Default::default(),
68 results: 5,
69 stopovers: Default::default(),
70 #[cfg(feature = "polylines")]
71 polylines: Default::default(),
72 bike_friendly: Default::default(),
73 tickets: true,
74 start_with_walking: true,
75 accessibility: Default::default(),
76 transfers: TransferOptions::default(),
77 transfer_time: Duration::zero(),
78 arrival: Default::default(),
79 departure: Default::default(),
80 products: Default::default(),
81 tariff_class: TariffClass::Second,
82 language: Default::default(),
83 loyalty_card: Default::default(),
84 passenger_age: Default::default(),
85 }
86 }
87 }
88
89 /// The response for [`Provider::journeys`](crate::Provider::journeys)
90 #[derive(Debug, Clone)]
91 pub struct JourneysResponse {
92 /// Reference to query earlier, used in [`JourneysOptions::earlier_than`].
93 pub earlier_ref: Option<String>,
94 /// Reference to query later, used in [`JourneysOptions::later_than`].
95 pub later_ref: Option<String>,
96 /// The list of journeys which is the result of the request.
97 pub journeys: Vec<Journey>,
98 }