-
Notifications
You must be signed in to change notification settings - Fork 26
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
Remove ToWkt? #73
Comments
It's more discoverable than |
@lnicola Are you currently using |
Ah, no, I'm not using it, but as a user I'd be fine with any reasonable API. |
New user here. As a user, I'd love to see (and am yet to find) an easy way to convert from geo-types to Wkt for the purposes of getting the WKT string representation. If ye permit, I can make a PR in the next hours with such impls that would make life much easier. |
It's used in a few places at least: https://github.com/search?l=&q=wkt%3A%3AToWkt+language%3ARust&type=code Some additional uses here, but includes some false positives from identically named traits: https://github.com/search?l=&q=ToWkt+language%3ARust&type=code Apart from arguably being more discoverable, there might be a reason to keep it as a means of including helper methods liek the |
I don't think it is actually more discoverable. For instance, it is another thing to bring into scope that you have to search the source code to know of (which I had to do). Also, it seems like adding unrelated things to a trait that was designed to convert things to Wkt. |
I really don't think |
less than 50 usages is a good number, pretty low, and a good opportunity to improve the abstractions this crate has to offer |
I'm on the fence here. I agree that there isn't much usage (looks like three or so active crates), so deprecating it (we wouldn't be removing it immediately anyway, in line with our "try not to make dependent crate maintainers miserable" policy) isn't a major concern. I like both #88 and #89's new method, fwiw. |
Can you expound on this? Did you have something specific in mind? Are you thinking something more like the hypothetical traits you mentioned in #88:
If I'm understanding correctly, I think this is a great idea, and actually close to what I was going for. For the common use case, I think the exposure of the So to be clear, I'm imagining most people to use as proposed in #88, I think you're advocating for:
The new But I think still easier for people would be something like this:
Is there a different way you imagine achieving this? |
This seems unambiguously more ergonomic to me. |
I just think that the current design of the
I agree with you in that people (likely) never want another struct to deal with, we already have the ones in
Yes, it does look better, it is less code, it is cleaner. It is just the internals what bother me. So what are you proposing If none of this wkt-specific structs existed and it was just the one Of course, that's a very heavy re-design and api-incompatible change, but I think it would be a great candidate for a |
Sure, granted!
Thanks for the response. To help me understand a little more concretely, could you provide any straw-man examples — What might a user of this crate write to accomplish the tasks you've outlined? |
What I would aim to achieve is something like this for serialization: // the only thing to bring into scope
use wkt::Wkt;
// can use not only a Geometry but any individual type
let thing = geo_types::Polygon::new(...); // or Triangle, or something else
// write to writer
thing.write_wkt(&mut writer).unwrap();
// get string
let wkt = thing.wkt(); (yes, it does look exactly as you proposed for the string part). And for parsing: let thing: geo_types::Polygon = wkt::parse("POLYGON (...)").unwrap(); If adding missing structs to the As for having a WKT representation for your own structs I can see something like this: use wkt::{Wkt, TriangleWkt, PointLike};
struct MyPoint(i32, i32);
struct MyTriangle {
p1: MyPoint,
p2: MyPoint,
p3: MyPoint,
}
impl PointLike for MyPoint {
fn get_x(&self) -> String { todo!() }
fn get_y(&self) -> String { todo!() }
fn get_z(&self) -> Option<String> { None }
}
impl TriangleWkt for MyTriangle {
type Point = MyPoint;
fn get_points(&self) -> [Self::Point; 3] { todo!() }
fn with_z(&self) -> bool { false }
}
let t = MyTriangle { ... };
let wkt = t.wkt(); // String WKT
t.write_wkt(&mut writer).unwrap(); // to IO |
Thanks for laying out an example of what you were envisioning. I feel like I'm pretty much aligned with this part.
I've got a couple questions about this part - First, Secondly - how does this compare when laid next to #92, where I've implemented ToWkt directly on the inner Geometry variants. I understand it's not exactly what you prescribed, but it seems to solve much of the same problems.
Going back to what you said a while ago, I don't think this is a very pressing concern with the wkt crate at this point. I feel like we're pretty free to break API's so long as we allow a deprecation cycle. I'm more conservative about breaking changes in the geo-types crate, since so many crates rely on the api, but I think it's less of an issue in wkt. And not really an issue at all if we provide a deprecation path. |
Oh and note that I separated
(On a side note... I wonder if there's any real value at this point between Wkt vs Geometry, and if it'd be possible to consolidate them into a single type. It used to be that Wkt had potentially many geometries, but we switched it to be 1:1 a little while ago.) |
for some reason I thought that Triangle was in Wkt but not in geo-types. My bad. If Wkt types are a subset of geo-types then it makes it even easier to use geo-types instead of wkt's own for deserialization.
For points it is simple, but for mulilinestings it kind of becomes a burden having to build another struct just to have a WKT string |
So I guess my question at this point would be, why are the Wkt structs necessary and why the ones in geo-types weren't used? |
That's a good point. Keep in mind that these are only the default implementations on the trait. Your type (or geo-types) for that matter could implement
I can't speak to the history. Two reasons that currently exist:
In any case, I'm going to close this issue at this point. The trait now has some other usage and it seems like the remaining concerns expressed here are being tracked in their own issues. (Feel free to re-open if I'm wrong) |
Does this get used anywhere? If so seems like we could replace usages with
Into<ToWkt>
The text was updated successfully, but these errors were encountered: