Since my Ph.D. days, I maintain a small Rust library for parsing and using the benchmark maps of the MovingAI suite: a popular (at least in academia) collection of benchmark maps and scenarios designed to measure the performance of pathfinding algorithms.
This week I released version 2.1.0. It is not a big change, but it is a breaking change and I care for my semantic versioning. At least for libraries.
The main changes are that I vastly reduced chance triggering panic
when parsing malformed data. In fact, in Rust, it is not good practice to make a library panic for recoverable errors: it is messy for a library to dictate to the host application how they should handle errors. It is kinda bad that I left so many “panics” for so long.
The idiomatic way to handle errors is with Result
. So, for instance, I changed this block:
|
|
with this
|
|
In the old version, if value.parse
returned an error, the library panicked with a message. Now, the library maps the error in an InvalidData
Error
and returns the error. Much more idiomatic.
There are other small places where I followed a similar approach and the result is that the library is now 100% panic-free (or, at least, it should).