5.0 version of the geos crate, the binding of the Geometry Engine Open Source C library 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!
To sum up changes:
ContextHandle(which is the object which makes types thread-safe).
geos::init(and therefore, no need on our side to cleanup on exit).
geofeature if you want to use them.
Alongside those big changes, some smaller ones like the replacement of skeptic with 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:
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):
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>>);
Another nice add is the add of the
WKTWriter types. Convenient methods over other types to generate outputs are still available (thinking about
to_wkt_precision). Now it's possible to change how many decimals you want, the number of output dimensions, etc...
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.
Previous articleGNOME+Rust Hackfest #5 in Berlin
Next articleKeeping Rust projects' README.md code examples up-to-date