georust / wkt

Rust read/write support for well-known text (WKT)
https://crates.io/crates/wkt
Apache License 2.0
50 stars 25 forks source link

impl ToWkt for inner geo_type variants, allow non-geotypes to impl ToWkt #92

Closed michaelkirk closed 2 years ago

michaelkirk commented 2 years ago

Draft because it's based on #89, so please review that first. update: merged!

The user benefit here is the implementation of ToWkt directly on the inner geometry enums so...

instead of:

let point: geo_types::point!(x: 1.0, y: 2.0);
let geo_geometry = geo_types::Geometry::from(point);
let string = geo_geometry.wkt_string();
assert_eq!("POINT(1 2)", string);

you can do:

let point: geo_types::point!(x: 1.0, y: 2.0);
let string = point.wkt_string();
assert_eq!("POINT(1 2)", string);

I also wanted to detangle ToWkt from geo-types, so that (hypothetical) non-geo-types users could implement it.

The majority of the lines changed are in ToWkt for non-geotypes, but it's a misleading large diff (sorry). Largely it's a cut and paste job: I cut the geo-types specific code from towkt.rs and pasted it into the new geo_types_to_wkt.rs.

For symmetry, and to better reflect it's functionality, I renamed the conversions module to geo_types_from_wkt.

michaelkirk commented 2 years ago

Ok, this is ready for review!

michaelkirk commented 2 years ago

Anyone available to review — maybe @categulario or @urschrei ?

michaelkirk commented 2 years ago

bors r=urschrei

bors[bot] commented 2 years ago

Build succeeded: