georust/wkt

Avoid intermediate `Wkt` allocation for `ToWkt::wkt_string` for geo-types

michaelkirk opened this issue · 0 comments

Currently geo-types uses the default implementation of wkt_string

fn wkt_string(&self) -> String {
    self
        .to_wkt() // <-- this allocates a Wkt struct
        .to_string()
}

Instead we could write an individual implementation for each geometry type that doesn't rely on first converting to a Wkt struct. e.g.

impl ToWkt for geo_types::Point {
    ...
    fn wkt_string(&self) -> String {
        format!("POINT({} {})", self.x, self.y)
    } 
}

There might be better and worse ways to do this WRT code re-use of the existing serialization methods on Wkt.