During my development of cellular_raza, I often came across the task of
comparing floating point numbers, especially during testing.
The Rust ecosystem has the aprox crate which is popular for
this use-case and widely used.
But the crate was missing derive macros for the AbsDiffEq and RelativeEq traits.
So I decided to fix this by providing an external crate approx-derive which addresses this
problem.
Functionality
The crate only provides the two derive macros AbsDiffEq and RelativeEq which generate
implementations of the identically-named traits.
It relies mainly on syn for parsing code,
and quote for generating code.
The following example shows how to use the derive macro. During the development and usage of this crate, I have added multiple features (see docs.rs/approx-derive).
|
|
Approxim
At the time of writing, the approx crate has not been
updated since $\approx$ 3 years and many PRs and feature requests have been ignored.
Furthermore, derive macros have not been added to the crate.
For this reason, I have forked approx, creating
approxim which includes all open PRs as well as derive
macros.
In order to provide a working solution for two crates with different names, I needed to infer the
name of the crate automatically.
I guarded this functionality behind the infer_name feature which does not have to be activated
when using with approx.
Although this crate exists, I hope that my solution for derive macros will be incorporated within
approx at some point in the future.
Update (02/2026)
I have now taken over maintainership from brendanzab for the approx crate and will release the additional features in upcoming versions.