Thoughts on Learning Rust
I’ve been really enjoying Rust. The language has many of the parts I like about
Haskell: higher-kinded types, algebraic data types (data
in Haskell; enum
in
Rust), Result
and Option
everywhere, auto-deriving, and so on. But it also
has more of a focus on “real-world” work. I personally prefer being able to use
slightly “uglier”, imperative-style programming when it makes sense. Rust is
that delightful combination.
Plus, Rust has truly spectacularly helpful error messages. I’ve often followed the advice in the error message and gotten exactly the behavior I originally wanted.
Learning enough Rust to be effective
So, how’d I start learning Rust?
I very highly recommend the Rust Book. It answered the questions I had and even proactively answered some questions I hadn’t thought of yet. It’s a lovely mix of practical exercises and the theory behind Rust’s design. I also went through rustlings, a set of exercises to test your Rust knowledge.
Then I started building. I’ve built a tool that recursively lists all files by modification date, a tool to show all URLs open in Firefox, and the one I’m most proud of: a program to slice and dice HTML. It’s called Candle.
Candle
Candle lets you use CSS selectors to slice and dice any HTML on the command line. It can also pretty-print any HTML. Candle uses Firefox’s HTML parsing engine (named Servo), so it has real-world parsing experience behind it.
Here’s a short demonstration of Candle, printing some text and a link:
$ curl https://daringfireball.net | candle '.article h1 a {text}, .article h1 a attr{href}'
Apple Addresses Siri Privacy Protections
https://daringfireball.net/2019/08/apple_siri_privacy
Siri, Privacy, and Trust
https://daringfireball.net/2019/08/siri_privacy_trust
Superhuman and Email Privacy
https://daringfireball.net/2019/07/superhuman_and_email_privacy
I write a lot of Ruby, and one of the nicest parts of Rust is how fast it is. It lets me use a lot of fancy features, but compiles them down into extremely fast code. Candle consistently runs in about 50ms for anything I throw at it, which makes me much more likely to use it. I’m a big fan of Rust.