valhalla_client/costing/mod.rs
1pub mod auto;
2pub mod bicycle;
3pub mod motor_scooter;
4pub mod motorcycle;
5pub mod multimodal;
6pub mod pedestrian;
7pub mod transit;
8pub mod truck;
9
10pub use auto::AutoCostingOptions;
11pub use bicycle::BicycleCostingOptions;
12pub use motor_scooter::MotorScooterCostingOptions;
13pub use motorcycle::MotorcycleCostingOptions;
14pub use multimodal::MultimodalCostingOptions;
15pub use pedestrian::PedestrianCostingOptions;
16use serde::Serialize;
17pub use transit::TransitCostingOptions;
18pub use truck::TruckCostingOptions;
19
20#[derive(Serialize, Clone, Debug, PartialEq)]
21#[serde(tag = "costing", content = "costing_options")]
22#[allow(clippy::large_enum_variant)]
23pub enum Costing {
24 /// Standard costing for driving routes by car, motorcycle, truck, and so on.
25 ///
26 /// Obeys automobile driving rules, such as access and turn restrictions.
27 /// This provides a short time path (though not guaranteed to be the shortest time) and
28 /// uses intersection costing to minimize turns and maneuvers or road name changes.
29 /// Routes also tend to favor highways and higher classification roads,
30 /// such as motorways and trunks.
31 #[serde(rename = "auto")]
32 Auto(AutoCostingOptions),
33
34 /// Standard costing for travel by bicycle.
35 ///
36 /// Has a slight preference for using cycleways or roads with bicycle lanes.
37 /// Bicycle routes follow regular roads when needed, but avoid roads without bicycle access.
38 #[serde(rename = "bicycle")]
39 Bicycle(BicycleCostingOptions),
40
41 /// Standard costing for bus routes.
42 ///
43 /// Bus costing inherits the [`Costing::Auto`] behaviors, but checks for bus access on the roads.
44 #[serde(rename = "bus")]
45 Bus(AutoCostingOptions),
46 /// A combination of pedestrian and bicycle.
47 ///
48 /// Use bike share station (indicated by [`amenity:bicycle_rental`](https://wiki.openstreetmap.org/wiki/Tag:amenity%3Dbicycle_rental)) to change the travel mode
49 #[serde(rename = "bikeshare")]
50 Bikeshare(BicycleCostingOptions),
51 /// Standard costing for trucks.
52 ///
53 /// Truck costing inherits the [`Costing::Auto`] behaviors, but checks for:
54 /// - truck access,
55 /// - width/height restrictions and
56 /// - weight limits
57 #[serde(rename = "truck")]
58 Truck(TruckCostingOptions),
59 /// Standard costing for taxi routes.
60 ///
61 /// Taxi costing inherits the [`Costing::Auto`] behaviors, but checks and favors
62 /// taxi lane access on roads.
63 #[serde(rename = "taxi")]
64 Taxi(AutoCostingOptions),
65 /// Standard costing for travel by motor scooter or moped.
66 ///
67 /// By default, this will avoid higher class roads unless the country overrides allows motor
68 /// scooters on these roads. Motor scooter routes follow regular roads when needed,
69 /// but avoid roads without motor_scooter, moped, or mofa access.
70 #[serde(rename = "motor_scooter")]
71 MotorScooter(MotorScooterCostingOptions),
72 /// Standard costing for travel by motorcycle.
73 ///
74 /// This costing model provides options to tune the route to take roadways (road touring) vs.
75 /// tracks and trails (adventure motorcycling).
76 #[serde(rename = "motorcycle")]
77 Motorcycle(MotorcycleCostingOptions),
78 /// Combines different modalities.
79 ///
80 /// **Currently supports pedestrian and transit.**
81 /// In the future, multimodal will support a combination of all of the above.
82 #[serde(rename = "multimodal")]
83 Multimodal(MultimodalCostingOptions),
84 /// Standard walking route that excludes roads without pedestrian access.
85 ///
86 /// In general, pedestrian routes are the shortest distance with the following exceptions:
87 /// - walkways and footpaths are slightly favored and
88 /// - steps or stairs and alleys are slightly avoided
89 #[serde(rename = "pedestrian")]
90 Pedestrian(PedestrianCostingOptions),
91}
92
93impl Default for Costing {
94 fn default() -> Self {
95 Self::Auto(Default::default())
96 }
97}
98
99#[cfg(test)]
100mod test {
101 use super::*;
102 #[test]
103 fn serialisation() {
104 assert_eq!(
105 serde_json::to_value(Costing::default()).unwrap(),
106 serde_json::json!({"costing": "auto", "costing_options": {"auto":{}}})
107 );
108 }
109}