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