Skip to content

Commit

Permalink
Pass test, make stop name and desc optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed Feb 23, 2024
1 parent 8cb5a1e commit 6c4cd0a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/gtfs_raw_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion examples/gtfs_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion examples/gtfs_reading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion examples/raw_gtfs_reading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")));
}
}
6 changes: 3 additions & 3 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ pub struct Stop {
pub code: Option<String>,
///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<String>,
/// Description of the location that provides useful, quality information
#[serde(default, rename = "stop_desc")]
pub description: String,
pub description: Option<String>,
/// Type of the location
#[serde(default)]
pub location_type: LocationType,
Expand Down Expand Up @@ -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("")))
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ fn display() {
format!(
"{}",
Stop {
name: "Sorano".to_owned(),
name:Some("Sorano".to_owned()),
..Stop::default()
}
)
Expand All @@ -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()
}
)
Expand All @@ -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()
}
)
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 6c4cd0a

Please sign in to comment.