gistools/readers/gbfs/schema_v2/
geofencing_zones.rs

1use crate::readers::gbfs_bool_or_int;
2use alloc::{string::String, vec::Vec};
3use s2json::{FeatureCollection, MValue, ValuePrimitive};
4use serde::{Deserialize, Serialize};
5
6/// # GBFS Geofencing Zones Schema V2.3, V2.2, V2.1, OR V2.0
7/// Describes geofencing zones and their associated rules and attributes (added in v2.1-RC).
8///
9/// ## Links
10/// - [GBFS Specification V2.3](https://github.com/MobilityData/gbfs/blob/v2.3/gbfs.md#geofencing_zonesjson)
11/// - [GBFS Specification V2.2](https://github.com/MobilityData/gbfs/blob/v2.2/gbfs.md#geofencing_zonesjson)
12/// - [GBFS Specification V2.1](https://github.com/MobilityData/gbfs/blob/v2.1/gbfs.md#geofencing_zonesjson)
13pub type GBFSGeofencingZonesV2 = GBFSGeofencingZonesV23;
14
15/// GBFS V3: Restrictions that apply within the area of the polygon.
16#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, ValuePrimitive)]
17pub struct GBFSGeofencingZonesV2PropertiesRule {
18    // /// Array of vehicle type IDs for which these restrictions apply.
19    // pub vehicle_type_id: Option<Vec<String>>,
20    ///  Is the undocked ride allowed to start and end in this zone?
21    #[serde(deserialize_with = "gbfs_bool_or_int")]
22    pub ride_allowed: bool,
23    /// Is the ride allowed to travel through this zone?
24    #[serde(deserialize_with = "gbfs_bool_or_int")]
25    pub ride_through_allowed: bool,
26    /// Maximum speed allowed, in kilometers per hour.
27    /// **Minimum**: 0
28    pub maximum_speed_kph: Option<f64>,
29    /// Vehicle MUST be parked at stations defined in station_information.json within this geofence zone.
30    pub station_parking: Option<bool>,
31}
32
33/// Properties of a geofencing zone
34#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, MValue)]
35pub struct GBFSGeofencingZonesV2Properties {
36    /// Public name of the geofencing zone.
37    #[serde(default)]
38    pub name: String,
39    /// Start time of the geofencing zone in RFC3339 format.
40    /// **format** date-time
41    pub start: Option<String>,
42    /// End time of the geofencing zone in RFC3339 format.
43    /// **format** date-time
44    pub end: Option<String>,
45    /// Array of rules defining restrictions within the geofence.
46    pub rules: Option<Vec<GBFSGeofencingZonesV2PropertiesRule>>,
47}
48
49/// Container for GeoJSON FeatureCollection of geofencing zones
50#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
51pub struct GBFSGeofencingZonesV2Data {
52    /// GeoJSON FeatureCollection of geofencing zones
53    pub geofencing_zones: FeatureCollection<(), GBFSGeofencingZonesV2Properties, MValue>,
54}
55
56/// # GBFS Geofencing Zones V2.3
57/// Describes geofencing zones and their associated rules and attributes (added in v2.1-RC).
58///
59/// ## Links
60/// - [GBFS Specification](https://github.com/MobilityData/gbfs/blob/v2.3/gbfs.md#geofencing_zonesjson)
61#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
62pub struct GBFSGeofencingZonesV23 {
63    /// Last time the data in the feed was updated in POSIX time.
64    /// **Minimum**: 1450155600
65    pub last_updated: u64,
66    /// Number of seconds before the data in the feed will be updated again (0 if the data should always be refreshed).
67    /// **Minimum**: 0
68    pub ttl: u64,
69    /// GBFS version number to which the feed conforms, according to the versioning framework.
70    /// **Const**: 2.3
71    pub version: String,
72    /// Contains geofencing information for the system.
73    pub data: GBFSGeofencingZonesV2Data,
74}
75
76/// # GBFS Geofencing Zones V2.2
77/// Describes geofencing zones and their associated rules and attributes (added in v2.1-RC).
78///
79/// ## Links
80/// - [GBFS Specification](https://github.com/MobilityData/gbfs/blob/v2.2/gbfs.md#geofencing_zonesjson)
81#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
82pub struct GBFSGeofencingZonesV22 {
83    /// Last time the data in the feed was updated in POSIX time.
84    /// **Minimum**: 1450155600
85    pub last_updated: u64,
86    /// Number of seconds before the data in the feed will be updated again (0 if the data should always be refreshed).
87    /// **Minimum**: 0
88    pub ttl: u64,
89    /// GBFS version number to which the feed conforms, according to the versioning framework.
90    /// **Const**: 2.2
91    pub version: String,
92    /// Contains geofencing information for the system.
93    pub data: GBFSGeofencingZonesV2Data,
94}
95
96/// # GBFS Geofencing Zones V2.1
97/// Describes geofencing zones and their associated rules and attributes (added in v2.1-RC).
98///
99/// ## Links
100/// - [GBFS Specification](https://github.com/MobilityData/gbfs/blob/v2.1/gbfs.md#geofencing_zonesjson)
101#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
102pub struct GBFSGeofencingZonesV21 {
103    /// Last time the data in the feed was updated in POSIX time.
104    /// **Minimum**: 1450155600
105    pub last_updated: u64,
106    /// Number of seconds before the data in the feed will be updated again (0 if the data should always be refreshed).
107    /// **Minimum**: 0
108    pub ttl: u64,
109    /// GBFS version number to which the feed conforms, according to the versioning framework.
110    /// **Const**: 2.1
111    pub version: String,
112    /// Contains geofencing information for the system.
113    pub data: GBFSGeofencingZonesV2Data,
114}