Open gergelytraveltime opened 3 months ago
Thank you for the code review.
.expect()
calls was to panic when an error which cannot be recovered from (without assuming some default behaviour) occurred.DecimalLon
I had a similar error mapping as for DecimalLat
, but because I allowed unnormalized longitudes, I removed it. Nevertheless, maybe I should implement back the limit, but in range [-360,360].CC: @PKJonas, @danielnaumau
Related to 2.
, this part seems a bit odd:
#[serde(rename="coordinates", skip_serializing)]
pub polygons: Vec<Polygon>,
#[serde(skip_deserializing)]
pub matched_locations: Vec<Location>,
I'm not familiar with Rust but skip_serializing
and skip_deserializing
feel like a code smell, like you're making a single type do the work of two different types: a Region
like you have, and a MatchResult
(or something) which would hold the region name and matched locations.
A bit more on point 2.:
It would be good to avoid mutable variables/data in your code, like with regions. It'd be better if you created a new type.
We are good with your proposals, please try avoid any ambiguity for 4. and 5., make error messages crystal-clear (also for the reviewer/read of your code) and try to ensure to really test that behavior in unit tests.
Re 1.
: when using .expect this way, what would be the user experience if the user had multiple errors? Say if both region and location files had errors in them, or one had an error and one had a typo in the path.
The answer would suggest why collecting errors is nice even if you can't recover from any of them.
impl<'de> Deserialize<'de> for DecimalLon { fn deserialize(deserializer: D) -> Result<DecimalLon, D::Error>
where
D: Deserializer<'de>,
{
Ok(DecimalLon::new(f64::deserialize(deserializer)?))
}
}