Skip to content
New issue

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

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

Already on GitHub? # to your account

specific errors and try_into for inner geo-types #57

Merged
merged 1 commit into from
Feb 10, 2021
Merged

Conversation

michaelkirk
Copy link
Member

@michaelkirk michaelkirk commented Jan 30, 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.

DRAFT: depends on georust/geo#614 being released first.

Add TryFrom for converting directly to geo_types::Geometry enum members.

let ls: geo_types::LineString = geo_types::LineString::try_from(wkt).unwrap();

Previously it was:

let geom: geo_types::Geometry = geo_types::Geometry::from(wkt).unwrap();
let ls: geo_types::LineString = geo_types::LineString::try_from(geom).unwrap();

This introduced two new error cases, so I've also introduced thiserror which solves #49

FIXES #49

}
// currently only one error type in geo-types error enum, but that seems likely to change
#[allow(unreachable_patterns)]
other => Error::External(Box::new(other)),
Copy link
Member Author

Choose a reason for hiding this comment

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

I thought it was worth future-proofing, so we don't have to bump WKT's minimum version of geo-types again if we add to the error enum.

@urschrei
Copy link
Member

This is a really big ergonomic improvement; the enum is really useful, but it's been historically awkward to work with and this removes a lot of that friction 👍👍👍

bors bot added a commit to georust/geo that referenced this pull request Feb 6, 2021
614: Specify the details of conversion failures in an exported error enum r=michaelkirk a=michaelkirk

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md).
- [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

I came across this while trying to improve ergonomics of the WKT crate, which relies on this conversion logic. (see georust/wkt#57)

I *think* this is not a breaking change (see comment inline), but would appreciate confirmation. If I'm wrong, and it indeed is a breaking change, I'd prefer to hold off on merging it for now. 

Co-authored-by: Michael Kirk <michael.code@endoftheworl.de>
@michaelkirk michaelkirk marked this pull request as ready for review February 10, 2021 18:31
@michaelkirk
Copy link
Member Author

Ok - updated now that the requisite geo-type 0.7.1 has been published.

Are you OK with merging this @urschrei?

@urschrei
Copy link
Member

Yep, lgtm!

@michaelkirk
Copy link
Member Author

bors r=urschrei

Excellent thanks!

@bors
Copy link
Contributor

bors bot commented Feb 10, 2021

Build succeeded:

@bors bors bot merged commit 9a1eef4 into master Feb 10, 2021
@michaelkirk michaelkirk deleted the mkirk/errors branch February 24, 2022 17:34
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

displayable errors: the trait StdError is not implemented for wkt::conversion::Error
2 participants