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