georust / wkt

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

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

Open michaelkirk opened 2 years ago

michaelkirk commented 2 years ago

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.