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::request::{ Request, transit_mode::TransitMode, }; // use impl<'a> Request<'a> { /// 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((vec![TransitMode::Rail]) /// ``` /// /// * Set preferred transit modes to bus and subway: /// ```rust /// .with_transit_modes(vec![ /// TransitMode::Bus, /// TransitMode::Subway /// ]) /// ``` pub fn with_transit_mode(&'a mut self, transit_mode: TransitMode) -> &'a mut Request { // Add restiction to Request struct. match &mut self.transit_modes { // If there are no transit modes in the request struct, initialize: None => self.transit_modes = Some(vec![transit_mode]), // If there are already transit modes, append to them: Some(transit_modes) => transit_modes.push(transit_mode), } // match // 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 Vec. This example sets preferred transit modes to bus /// and subway: /// /// ```rust /// .with_transit_modes(vec![ /// TransitMode::Bus, /// TransitMode::Subway, /// ]) /// ``` pub fn with_transit_modes(&'a mut self, transit_modes_slice: &[TransitMode]) -> &'a mut Request { // Add transit_modes to Request struct. match &mut self.transit_modes { // If there are no transit modes in the request struct, initialize: None => self.transit_modes = Some(transit_modes_slice.to_vec()), // If there are already transit modes, append to them: Some(transit_modes) => for transit_mode in transit_modes_slice { transit_modes.push(transit_mode.to_owned()) } // case } // match // Return modified Request struct to caller. self } // fn } // impl