diff --git a/examples/gtfs_raw_reader.rs b/examples/gtfs_raw_reader.rs index 1622fb9..a76eee8 100644 --- a/examples/gtfs_raw_reader.rs +++ b/examples/gtfs_raw_reader.rs @@ -11,5 +11,5 @@ fn main() { let routes = gtfs.routes.expect("impossible to read routes"); let route_1 = routes.first().expect("no route"); - println!("{}: {:?}", route_1.short_name, route_1); + println!("{}: {:?}", route_1.short_name.as_ref().unwrap(), route_1); } diff --git a/examples/gtfs_reader.rs b/examples/gtfs_reader.rs index f7851ac..5c08c75 100644 --- a/examples/gtfs_reader.rs +++ b/examples/gtfs_reader.rs @@ -11,5 +11,5 @@ fn main() { println!("there are {} stops in the gtfs", gtfs.stops.len()); let route_1 = gtfs.routes.get("1").expect("no route 1"); - println!("{}: {:?}", route_1.short_name, route_1); + println!("{}: {:?}", route_1.short_name.as_ref().unwrap(), route_1); } diff --git a/examples/gtfs_reading.rs b/examples/gtfs_reading.rs index 30fd882..c9d81e5 100644 --- a/examples/gtfs_reading.rs +++ b/examples/gtfs_reading.rs @@ -11,5 +11,5 @@ fn main() { println!("there are {} stops in the gtfs", gtfs.stops.len()); let route_1 = gtfs.routes.get("1").expect("no route 1"); - println!("{}: {:?}", route_1.short_name, route_1); + println!("{}: {:?}", route_1.short_name.as_ref().unwrap(), route_1); } diff --git a/examples/raw_gtfs_reading.rs b/examples/raw_gtfs_reading.rs index 2227a47..fb6d045 100644 --- a/examples/raw_gtfs_reading.rs +++ b/examples/raw_gtfs_reading.rs @@ -9,6 +9,6 @@ fn main() { raw_gtfs.print_stats(); for stop in raw_gtfs.stops.expect("impossible to read stops.txt") { - println!("stop: {}", stop.name); + println!("stop: {}", stop.name.unwrap_or(String::from(""))); } } diff --git a/src/objects.rs b/src/objects.rs index 3590c48..da58107 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -153,10 +153,10 @@ pub struct Stop { pub code: Option, ///Name of the location. Use a name that people will understand in the local and tourist vernacular #[serde(rename = "stop_name")] - pub name: String, + pub name: Option, /// Description of the location that provides useful, quality information #[serde(default, rename = "stop_desc")] - pub description: String, + pub description: Option, /// Type of the location #[serde(default)] pub location_type: LocationType, @@ -212,7 +212,7 @@ impl Id for Stop { impl fmt::Display for Stop { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.name) + write!(f, "{}", self.name.clone().unwrap_or(String::from(""))) } } diff --git a/src/tests.rs b/src/tests.rs index f5d9fbe..72e56a0 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -310,7 +310,7 @@ fn display() { format!( "{}", Stop { - name: "Sorano".to_owned(), + name:Some("Sorano".to_owned()), ..Stop::default() } ) @@ -321,7 +321,8 @@ fn display() { format!( "{}", Route { - long_name: "Long route name".to_owned(), + long_name: Some("Long route name".to_owned()), + short_name: None, ..Route::default() } ) @@ -332,7 +333,8 @@ fn display() { format!( "{}", Route { - short_name: "Short route name".to_owned(), + short_name: Some("Short route name".to_owned()), + long_name: None, ..Route::default() } ) @@ -415,7 +417,7 @@ fn read_interpolated_stops() { // the second stop have no departure/arrival, it should not cause any problems assert_eq!( gtfs.trips["trip1"].stop_times[1].stop.name, - "Stop Point child of 1" + Some("Stop Point child of 1".to_owned()) ); assert!(gtfs.trips["trip1"].stop_times[1].arrival_time.is_none()); }