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
use crate::{
    directions::{
        response::{
            directions_distance::DirectionsDistance,
            directions_duration::DirectionsDuration,
            driving_maneuver::DrivingManeuver,
            polyline::Polyline,
            transit_details::TransitDetails,
        }, // response
        travel_mode::TravelMode
    }, // directions
    latlng::LatLng,
}; // use
use serde::Deserialize;

/// Each element in the `steps` array defines a single step of the calculated
/// directions. A step is the most atomic unit of a direction's route,
/// containing a single step describing a specific, single instruction on the
/// journey. E.g. "Turn left at W. 4th St." The step not only describes the
/// instruction but also contains distance and duration information relating to
/// how this step relates to the following step. For example, a step denoted as
/// "Merge onto I-80 West" may contain a duration of "37 miles" and
/// "40 minutes," indicating that the next step is 37 miles/40 minutes from this
/// step.
///
/// When using the Directions API to search for transit directions, the steps
/// array will include additional [transit
/// details](https://developers.google.com/maps/documentation/directions/intro#TransitDetails)
/// in the form of a `transit_details` array. If the directions include multiple
/// modes of transportation, detailed directions will be provided for walking or
/// driving steps in an inner `steps` array. For example, a walking step will
/// include directions from the start and end locations: "Walk to Innes Ave &
/// Fitch St". That step will include detailed walking directions for that route
/// in the inner steps array, such as: "Head north-west", "Turn left onto
/// Arelious Walker", and "Turn left onto Innes Ave".

#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct Step {

    /// The distance covered by this step. This property may be undefined as the
    /// distance may be unknown.
    pub distance: DirectionsDistance,

    /// The typical time required to perform this step in seconds and in text
    /// form. This property may be undefined as the duration may be unknown.
    pub duration: DirectionsDuration,

    /// The ending location of this step.
    pub end_location: LatLng,

    /// Instructions for this step.
    pub html_instructions: String,

    /// Contains the action to take for the current step (turn left, merge,
    /// straight, etc.). This field is used to determine which icon to display.
    pub maneuver: Option<DrivingManeuver>,

    /// Contains a single `points` object that holds an [encoded polyline](https://developers.google.com/maps/documentation/utilities/polylinealgorithm) representation of the step. This polyline is an approximate (smoothed) path of the step. (Corresponds to `path` in the [Directions.Step interface](https://developers.google.com/maps/documentation/javascript/reference/directions#DirectionsStep).)
    pub polyline: Polyline,

    /// The starting location of this step.
    pub start_location: LatLng,

    /// Contains detailed directions for walking or driving steps in transit
    /// directions. Substeps are only available when travel_mode is set to
    /// "transit". The inner steps array is of the same type as steps.
    pub steps: Option<Vec<Step>>,

    /// Transit-specific details about this step. This property will be
    /// undefined unless the travel mode of this step is TravelMode::Transit.
    pub transit_details: Option<TransitDetails>,

    /// The mode of travel used in this step.
    pub travel_mode: TravelMode,

} // struct

impl Step {

    /// A helper function for destructuring (or serializing) the optional
    /// `maneuver` field. If the `ManeuverType` enum in the step is populated,
    /// this function will return it as a `String`. If the _ManeuverType_ enum
    /// is empty, this function will return `None`.
    /// ```rust
    /// let maneuver = step.get_maneuver();
    /// ```
    pub fn get_maneuver(&self) -> Option<String> {
        match &self.maneuver {
            Some(maneuver) => Some(String::from(maneuver)),
            None => None,
        } // match
    } // fn

} // impl