Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl serde::Deserialize for Wkt and Geometry (and helper function) #59

Merged
merged 6 commits into from
Feb 15, 2021

Conversation

woshilapin
Copy link
Contributor

@woshilapin woshilapin commented Feb 12, 2021

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

Copy link
Member

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me, thank you!

I'm going to leave it open for a few days before merging in case anyone else would like to review.

@michaelkirk
Copy link
Member

bors try

bors bot added a commit that referenced this pull request Feb 12, 2021
@bors
Copy link
Contributor

bors bot commented Feb 12, 2021

try

Build succeeded:

///
/// #[derive(serde::Deserialize)]
/// struct MyType {
/// #[serde(deserialize_with = "wkt::deserialize::deserialize_wkt_geometry")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can export the module to only do wkt::deserialize_geometry?

Copy link
Contributor Author

@woshilapin woshilapin Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought about something similar, I'm glad you proposed it. Done in f5e5d35.

use serde::Deserialize;
use std::convert::TryInto;
let geometry: Geometry<f64> = Geometry::deserialize(deserializer)?;
let geometry: geo_types::Geometry<f64> = geometry.try_into().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we export an error here?

very minor: wouldn't it be better to use std::convert::TryInto; just before using it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we don't want to unwrap here, thanks for noticing @antoine-de

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely forgot that .unwrap(), oops. Fixed in d5a8de3. I also reorganized the code a bit with a .and_then(), but please tell if you prefer the previous version, I can definitely change it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also made the helper function generic over the type T of Geometry<T> because the first version was useful for Geometry<f64> but was useless for Geometry<f32>. See commit be202f4.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes all look good to me, thank you!

@michaelkirk
Copy link
Member

bors try

bors bot added a commit that referenced this pull request Feb 13, 2021
@bors
Copy link
Contributor

bors bot commented Feb 13, 2021

try

Build failed:

///
/// #[derive(serde::Deserialize)]
/// struct MyType {
/// #[serde(deserialize_with = "wkt::deserialize_geometry")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, there is a special dance to do when a doc-test requires a feature flag.

We have a similar example here in proj which requires the optional geo-types feature:

https://github.com/georust/proj/blob/master/src/lib.rs#L175

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, forget that. This whole module is only included conditionally with the serde feature. I'm not immediately sure what to make of the CI failure. I can look at it further next week.

https://github.com/georust/wkt/runs/1891796241

src/lib.rs Outdated
extern crate serde;
#[cfg(feature = "serde")]
pub mod deserialize;
#[cfg(feature = "serde")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! it's failing because we need both serde and geo-types for this method.

Copy link
Contributor Author

@woshilapin woshilapin Feb 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, I failed this one. Nice CI setup to catch that by the way. Fixed in fe5e129.

Cargo.toml Outdated

[features]
default = ["geo-types"]
default = ["geo-types", "serde"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've seen in the ecosystem, Serde support is usually opt-in and not included as a default feature. If I had to guess, I'd say more often then not, users won't need Serde support when using this crate. Would love to hear from others

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you're right. It should probably not be included in default.

Copy link
Contributor Author

@woshilapin woshilapin Feb 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this was definitely not intended as I used this trick only locally to facilitate the development. Good catch, thank you 🙏 I amended the last commit.

Copy link
Member

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

Ok, I think this has gotten enough feedback. Thanks @woshilapin!

@bors
Copy link
Contributor

bors bot commented Feb 15, 2021

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants