So here’s my first Rust crate: codice_fiscale. It’s a first attempt to release crates aimed at solving tasks which are very common especially in web programming: validation of credit card numbers, shipping rates lookups, and loads of other things. Some of these tasks already have Rust crates dedicated to them, other’s still don’t.
This particular crate is mainly useful to Italian companies, as it allows to calculate, and especially to check, a codice fiscale, which is a code every Italian citizen has and is used in invoices, medical system, and a lot of other tasks which involve the government in some way or fiscal things.
By writing this crate, since I’m learning Rust, I had the occasion to understand a lot of things regarding this wonderful language and its toolchain. At the same time, I likely did something wrong, but luckily there is still time to fix these things in new versions of this crate.
So, here’s what I loved:
- The toolchain to build and publish module packages (crates, in Rust) is so straightforward and integrated that everybody is probably tempted to publish his code, which is a wonderful thing in the open source world.
- Writing tests is not only dead easy, it’s also fun.
- Writing documentation is straightforward as well: this reminds me of the excellent Perl documentation system.
- Errors reported by rustc are the best… they often tell you exactly what to do to fix them.
matchis so powerful and expressive!
And here are some notes about what I0’m still working on and what I’m still trying to fully understand:
- The error propagation system requires a lot of boilerplate, so I used (like, it seems, most developers do), and external crate: I chose failure which is great, but I still feel Rust should have something like this integrated in the language.
- I perfectly understand the reasons behind having both a
&strtype, but it still feels strange to have two different type for strings.
- I’m still unsure wether my constructor should move values or borrow a reference. For now they borrow references, but it’s still something - as a Rust newbie - I’m thinking about. Unfortunately, changing this in the future will break backward compatibility of the crate.
- I have a simple static HashMap, to initialize which I’m using lazy_static. It feels a bit overkill, so I’m considering the removal of this dependency by switching to a couple of arrays.
All in all, it was great fun, and I really hope this is just the beginning of my journey into the world of Rust.