gistools/readers/gtfs/schedule/
levels.rs

1use crate::readers::csv::parse_csv_as_record;
2use alloc::{collections::BTreeMap, string::String};
3use s2json::MValueCompatible;
4
5/// # Levels
6///
7/// **Conditionally Required**
8/// Describes levels in a station, useful with `pathways.txt`.
9/// Required if `pathways` include elevators (`pathway_mode=5`), otherwise optional.
10#[derive(Debug, Default, Clone, PartialEq, MValueCompatible)]
11pub struct GTFSLevel {
12    /// **Required**
13    /// Identifies a level in a station (`level_id`).
14    pub level_id: String,
15    /// **Required**
16    /// Numeric index indicating this level's relative position:
17    /// - 0 for ground level
18    /// - Positive above ground
19    /// - Negative below ground
20    pub level_index: i32,
21    /// **Optional**
22    /// Name of the level as displayed to the rider (e.g., "Mezzanine", "Platform").
23    pub level_name: Option<String>,
24}
25impl GTFSLevel {
26    /// Create a new GTFSLevel
27    pub fn new(source: &str) -> BTreeMap<String, GTFSLevel> {
28        let mut res = BTreeMap::new();
29        for record in parse_csv_as_record::<GTFSLevel>(source, None, None) {
30            res.insert(record.level_id.clone(), record);
31        }
32        res
33    }
34}