google_maps2/distance_matrix/request/with_restrictions.rs
1use crate::directions::request::avoid::Avoid;
2use crate::distance_matrix::request::Request;
3
4impl<'a> Request<'a> {
5 /// Specify a feature that routes should avoid.
6 ///
7 /// ## Arguments
8 ///
9 /// * `restrictions` ‧ A Vec containing a list of features that should be
10 /// avoided when possible when calculating the route, such as _ferries_,
11 /// _highways_, _indoor_ steps, and/or _tolls_.
12 ///
13 /// ## Description
14 ///
15 /// Indicates that the calculated route(s) should avoid the indicated
16 /// features. This parameter supports the following arguments:
17 ///
18 /// * `Avoid::Tolls` indicates that the calculated route should avoid toll
19 /// roads/bridges.
20 ///
21 /// * `Avoid::Highways` indicates that the calculated route should avoid
22 /// highways.
23 ///
24 /// * `Avoid::Ferries` indicates that the calculated route should avoid
25 /// ferries.
26 ///
27 /// * `Avoid::Indoor` indicates that the calculated route should avoid
28 /// indoor steps for walking and transit directions. Only requests that
29 /// include an API key or a Google Maps Platform Premium Plan client ID will
30 /// receive indoor steps by default.
31 ///
32 /// [Route Restrictions](https://developers.google.com/maps/documentation/directions/intro#Restrictions)
33 ///
34 /// Directions may be calculated that adhere to certain restrictions.
35 /// Restrictions are indicated by use of the avoid parameter, and an
36 /// argument to that parameter indicating the restriction to avoid.
37 ///
38 /// It's possible to request a route that avoids any combination of tolls,
39 /// highways and ferries by passing both restrictions.
40 ///
41 /// _Note_: the addition of restrictions does not preclude routes that
42 /// include the restricted feature; it simply biases the result to more
43 /// favorable routes.
44 ///
45 /// ## Examples:
46 ///
47 /// * Only avoid highways:
48 ///
49 /// ```rust
50 /// .with_restriction(Avoid::Highways)
51 /// ```
52 ///
53 /// * Multiple restrictions may be stacked together. This example avoids
54 /// tolls and ferries:
55 ///
56 /// ```rust
57 /// .with_restriction(Avoid::Tolls)
58 /// .with_restriction(Avoid::Ferries)
59 /// ```
60
61 pub fn with_restriction(&'a mut self, restriction: Avoid) -> &'a mut Self {
62 // Add restriction to Request struct.
63 self.restrictions = vec![restriction];
64 // Return modified Request struct to caller.
65 self
66 } // fn
67
68 /// Specify features that routes should avoid.
69 ///
70 /// # Example:
71 ///
72 /// * Alternatively, multiple restrictions may be passed in a single method
73 /// call by passing a slice. This example avoids tolls and ferries:
74 ///
75 /// ```rust
76 /// .with_restrictions(&[
77 /// Avoid::Tolls,
78 /// Avoid::Ferries,
79 /// ])
80 /// ```
81 ///
82 /// # Generics
83 ///
84 /// This method uses generics to improve ergonomics. The `C` generic is
85 /// intended to represent any collection that can be iterated over, and the
86 /// `A` generic is for any type that can be converted to the `Avoid`
87 /// type.
88
89 pub fn with_restrictions<C, A>(
90 &'a mut self,
91 restrictions: C,
92 ) -> &'a mut Self
93 where
94 C: IntoIterator<Item = A>,
95 A: Into<Avoid> {
96 // Add restrictions to Request struct.
97 self.restrictions = restrictions.into_iter().map(Into::into).collect();
98 // Return modified Request struct to caller.
99 self
100 } // fn
101} // impl