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
use crate::directions::TransitMode;
// -----------------------------------------------------------------------------
impl crate::distance_matrix::Request<'_> {
/// Specify the preferred mode of transit.
///
/// ## Arguments
///
/// * `transit_modes` ‧ The preference of the transit rider; what mode of
/// transit should the directions service prioritize? _Bus_, _Subway_,
/// _Train_, _Tram_, or _Rail_?
///
/// ## Description
///
/// Specifies one or more preferred modes of transit. This parameter may
/// only be specified for transit directions, and only if the request
/// includes an API key or a Google Maps Platform Premium Plan client ID.
/// The parameter supports the following arguments:
///
/// * `TransitMode::Bus` indicates that the calculated route should prefer
/// travel by bus.
///
/// * `TransitMode::Subway` indicates that the calculated route should
/// prefer travel by subway.
///
/// * `TransitMode::Train` indicates that the calculated route should prefer
/// travel by train.
///
/// * `TransitMode::Tram` indicates that the calculated route should prefer
/// travel by tram and light rail.
///
/// * `TransitMode::Rail` indicates that the calculated route should prefer
/// travel by train, tram, light rail, and subway. This is equivalent to
/// `TransitMode::Train|Tram|Subway`.
///
/// ## Examples:
///
/// * Set preferred transit mode to rail:
///
/// ```rust
/// .with_transit_mode(TransitMode::Rail)
/// ```
///
/// * Multiple modes may be stacked together. This example sets preferred
/// transit modes to bus and subway:
///
/// ```rust
/// .with_transit_mode(TransitMode::Bus)
/// .with_transit_mode(TransitMode::Subway)
/// ```
#[must_use] pub fn with_transit_mode(
mut self,
transit_mode: impl Into<TransitMode>
) -> Self {
// Add restiction to Request struct.
self.transit_modes.push(transit_mode.into());
// Return modified Request struct to caller.
self
} // fn
/// Specifies preferred modes of transit.
///
/// # Example:
///
/// * Alternatively, multiple transit modes may be passed in a single method
/// call by passing a slice. This example sets preferred transit modes to
/// bus and subway:
///
/// ```rust
/// .with_transit_modes(&[
/// TransitMode::Bus,
/// TransitMode::Subway,
/// ])
/// ```
///
/// # Generics
///
/// This method uses generics to improve ergonomics. The `C` generic is
/// intended to represent any collection that can be iterated over, and the
/// `T` generic is for any type that can be converted to the `TransitMode`
/// type.
#[must_use] pub fn with_transit_modes<C, T>(
mut self,
transit_modes: C
) -> Self
where
C: IntoIterator<Item = T>,
T: Into<TransitMode> {
// Add transit_modes to Request struct.
self.transit_modes.extend(transit_modes.into_iter().map(Into::into));
// Return modified Request struct to caller.
self
} // fn
} // impl