As my first rust project less trivial than guessing_game, I set out to create my own number type, similar to BigDecimal types in Java or Ruby (but putting aside the bigness feature). I’d love feedback on it, particularly idioms I’m missing or style suggestions.
The lib is defined here: https://github.com/duelinmarkers/rust-study/blob/master/decimal/src/lib.rs, and there are a couple of quickcheck tests here: https://github.com/duelinmarkers/rust-study/blob/master/decimal/tests/lib.rs.
One thing I’m aware of that would make sense for a “real” number type would be to implement the operator traits for references, as all the primitives do. That would mean three more impls per operator (for
self, &x, and
&self, &x). I haven’t done that (yet) because it seems laborious and like it would bloat the code quite a bit. Maybe there’s a terser way to do it with macros.
(The question of whether a decimal type should consider scale in its
impl Eq is interesting, but not the discussion I’m looking for, as it’s not Rust-specific, and I don’t intend for anyone to use this code.)