georust / geos

Rust bindings for GEOS
https://docs.rs/geos/
MIT License
122 stars 42 forks source link

Post for next release #71

Closed GuillaumeGomez closed 5 years ago

GuillaumeGomez commented 5 years ago
# New geos release

The `5.0` version of the [geos](https://crates.io/crates/geos) crate was just released! The last version came out not so long ago, however it lacked quite a number of things, starting with functions available in the C library. This new release changes everything. Time to write about what happened in this new version!

A quick note before starting: when "geos" is written, I'm talking about the Rust crate, when "GEOS" is written, I'm talking about the C library. Now that it's clear, let's start!

### Changes

To sum up changes:

 * geos objects are now thread-safe thanks to the switch to GEOS thread-safe functions.
 * GEOS versions are handled through features (if a function isn't available, it's very likely you forgot to enable a feature!).
 * All types have a `ContextHandle` (which is the object which makes types thread-safe).
 * No need anymore to call `geos::init` (and therefore, no need on our side to cleanup on exit).
 * A lot more of functions/types available.
 * A **lot** more of documentation (with examples!).
 * A **lot** more of tests (thanks to documentation).
 * Bridges with the geo crate are now optional. You need to enable the `geo` feature if you want to use them.

Alongside those big changes, some smaller ones like the replacement of [skeptic](https://crates.io/crates/skeptic) with [doc-comment](https://crates.io/crates/doc-comment) to test README file code examples now prevents `cargo` to rebuild the whole library everytime when it's being used as a dependency.

A renaming also happened:

 * `GGeom` became `Geometry`
 * `PreparedGGeom` became `PreparedGeometry`

### More control

For this new release, control over errors has been greatly improved. Now, almost every function returns a `GResult`. It can seem a bit annoying at first, but when an error triggers, you can find where it comes from **very** easily, and that was the goal.

You can then get more information on the error through the `ContextHandle` type which provides the following two methods (amongst others):

```Rust
pub fn get_last_error(&self) -> Option<String>;
pub fn get_last_notification(&self) -> Option<String>;

You can call them on any geos type through the ContextInteractions trait. But in case you want to be noticed when the error occurs directly without having to call this function, you can set a callback to be called:

pub fn set_error_message_handler(&self, ef: Option<Box<dyn Fn(&str) + Send + Sync + 'a>>);
pub fn set_notice_message_handler(&self, nf: Option<Box<dyn Fn(&str) + Send + Sync + 'a>>);

Outputs

Another nice add is the add of the WBKWriter and WKTWriter types. Convenient methods over other types to generate outputs are still available (thinking about to_wkt and to_wkt_precision). Now it's possible to change how many decimals you want, the number of output dimensions, etc...

Word of the end

All these changes were made with a clear focus on giving more control to the users while making it easier to use (thanks to the documentation and the examples too!). Feedbacks are very welcome so don't hesitate to open issues on the repository.

Good hacking!

mthh commented 5 years ago

This is great ! Many thanks @GuillaumeGomez !