--- Title: Rust is Incredibly Productive for CLIs Subtitle: "Donât let the tagline fool you: Rust is for more than just âsystems programming.â" Date: 2018-05-20 08:35 Tags: [Rust, programming languages] Category: tech Summary: > I built a little tool in Rust to convert an Evernote export file to Markdown. It was impressively easy. --- There are *reasons* Iâm a Rust fanboy. One of them is the kind of thing I proved out to myself todayâagain, because Iâve had this experience before, albeit not with anything quite this âcomplicated.â I built [a little tool](https://github.com/chriskrycho/evernote2md) in Rust to convert Evernote exports (in their custom `.enex` XML format) to Markdown files with YAML metadata headersâmostly just to see how quickly and effectively I could do it, because Iâve never actually had an excuse to use [Serde](https://serde.rs) and I thought this might be a nice spot to try it. Thereâs a lot this little library *doesnât* do. (Like include the creation and modification timestamps in the header, for example.) But all of those things would be *very* straightforward to do. I built this functioning little âscriptâ in about two hours. For context: Iâve taken multiple passes at this in Pythonâwhich in the way people normally think about these things should be way *easier*âand Iâve failed both times. Rustâs compiler just helps you out *so much* along the way, not only with the type-checking but with the really amazing metaprogramming capabilities you get with it. Being able to slap `#[derive(Deserialize)]` on a struct and a couple attributes on struct fields and having it Just Work⢠to deserialize XML into local types is mind-blowing. (The only thing I know of thatâs playing the same game is F^â¯^ type-providers. Iâd love to hear about similar capabilities in other languages!) Iâm basically at the point where if I need a small command-line tool, I write it in Rust, *not* in a conventional scripting language like Python, because the benefits I get more than outweigh whatever small extra amount of mental overhead there is. And thereâs not much of that mental overhead anyway for this kind of thing! As you can see [in the actual code](https://github.com/chriskrycho/evernote2md/blob/master/src/main.rs#L71), I make free and liberal use of [`expect`](https://doc.rust-lang.org/1.26.0/std/option/enum.Option.html) for this kind of tool. Itâs also hard to oversell the ecosystemâeven as relatively nascent as it is compared to some much older languages, the tools which exist are just really good. This project uses [Serde](https://serde.rs) for deserializing from XML and serializing to YAML; [Regex](https://github.com/rust-lang/regex); [Clap](https://clap.rs) for command line parsing; a nice little wrapper around [pandoc](https://pandoc.org); and, superpower even among superpowers, [Rayon](https://docs.rs/rayon/1.0.1/rayon/): free parallelization. Rust is, in short, *very productive* for things in this space. Far more than you might expect from the billing. Yes, itâs a âsystems programming languageâ and you can write operating systems with it. But itâs also just a really great tool for *all sorts* of domains, including little CLI tools like this one.