Writing some Rust libraries
Saturday, May 6th, 2023 14:55![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
The piece of software I've mostly been working on recently is still All is Cubes (posts). However, this one project has sprawled out into a lot of things to do with Rust.
For example, something about my coding style (or maybe my attention to error messages) seems to turn up compiler bugs — such as
#80772,
#88630,
#95324,
#95873,
#97205,
#104025,
#105645,
#108481, and
#109067. (Which is not to say that Rust is dreadfully buggy — on average, the experience is reliable and pleasant.) I'm also taking some steps into contributing to the compiler, so I can get some bugs (and pet peeves) fixed myself. (The first step, though, was simply running my own code against rustc
nightly builds, so I can help spot these kinds of bugs before they get released.)
I've also taken some code from All is Cubes and split it out into libraries that might be useful for others.
The first one was
exhaust
, a trait-and-macro library that provides the ability to take a type (that implements theExhaust
trait) and generate all possible values of that type. The original motivation was to improve on (for my purposes)strum::IntoEnumIterator
(which does this forenum
s but always leaves theenum
’s fields with theDefault
value) by generatingenum
s andstruct
s arbitrarily recursively.(Exhaustive iteration is perhaps surprisingly feasible even in bigger domains than a single
enum
; if you have a simple piece of arithmetic, for example, it only takes a few seconds to run it on every 32-bit integer or floating-point value, and look for specific outcomes or build a histogram of the results.)The second one, published just yesterday, is
rendiff
, a (slightly) novel image diffing algorithm which I invented to compare the output of All is Cubes’ renderer test cases. Its value is that it is able to compensate for the results of rounding errors on the positions of the edges of objects in the scene — instead of such errors counting against a budget of allowable wrong pixels, they're just counted as correct, by observing that they exist at a neighboring position in the other image.