gistools/readers/gtfs/schedule/
networks.rs

1use crate::readers::csv::parse_csv_as_record;
2use alloc::{collections::BTreeMap, string::String};
3use s2json::MValueCompatible;
4
5/// # Networks
6///
7/// **Conditionally Forbidden**
8/// Defines network identifiers. Used to group routes under a named network
9/// for fare leg rules. This file is forbidden if `network_id` exists in `routes.txt`,
10/// otherwise optional.
11#[derive(Debug, Default, Clone, PartialEq, MValueCompatible)]
12pub struct GTFSNetwork {
13    /// **Required**
14    /// Identifies a network (`network_id`). Must be unique in `networks.txt`.
15    pub network_id: String,
16    /// **Optional**
17    /// The name of the network as used by the local agency and its riders.
18    pub network_name: Option<String>,
19}
20impl GTFSNetwork {
21    /// Create a new GTFSNetwork
22    pub fn new(source: &str) -> BTreeMap<String, GTFSNetwork> {
23        let mut res = BTreeMap::new();
24        for record in parse_csv_as_record::<GTFSNetwork>(source, None, None) {
25            res.insert(record.network_id.clone(), record);
26        }
27        res
28    }
29}