Some checks failed
Create and publish a Docker image / build-and-push-image (push) Has been cancelled
31 lines
895 B
Rust
31 lines
895 B
Rust
use crate::traits::*;
|
|
use serde::{self, Deserialize, Deserializer};
|
|
|
|
pub fn de_string_or_int<'de, D>(deserializer: D) -> Result<i64, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
use serde::de::Error;
|
|
use serde_json::Value;
|
|
|
|
match Value::deserialize(deserializer)? {
|
|
Value::Number(n) => n.as_i64().ok_or_else(|| Error::custom("Invalid number")),
|
|
Value::String(s) => s.parse::<i64>().map_err(|_| Error::custom("Invalid string number")),
|
|
_ => Err(Error::custom("Expected a string or number")),
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct RouteStop {
|
|
pub route_id: String,
|
|
pub direction_id: i64,
|
|
#[serde(deserialize_with = "de_string_or_int")]
|
|
pub stop_id: i64,
|
|
pub stop_name: String,
|
|
pub stop_sequence: i64,
|
|
pub stop_lat: f64,
|
|
pub stop_lon: f64,
|
|
}
|
|
|
|
impl SeptaJson for RouteStop {}
|
|
impl SeptaJson for Vec<RouteStop> {}
|