I’m not a Rust expert by any means, but I’ve spent enough time with the language that I can write reasonable code with a bit of effort (and a lot of DuckDuckGo). However, I’ve found that I often hesitate to use it for my personal projects.
Rust is a large language. The sheer number of features and their complexity introduce so much cognitive overhead while writing code that I can’t always muster up the mental energy to use it for things I’m simply tinkering around with after work. It’s just not possible for me to keep the whole thing in my head.
If I was writing Rust for my day job, it would be a different matter. Using it to build production software every day would let me internalize it to the point that it would become mostly automatic. It would let me cement difficult concepts in my brain so that I wouldn’t have to go looking for explanations every five minutes (lifetimes, anyone?)
Sadly I only get to use Rust for one-off side-projects, which means I spend maybe two hours a week using it. This gives me barely enough time to get my code into a working state, let alone dive into things like the Rustonomicon or even macros.
I love Rust, so I’m going to continue using it despite my issues with it. I’ll just have to lower my expectations of the level of proficiency I can hope to attain with the language.
PS: somebody please give me a Rust job 😭
Everything I’ve built with Rust so far has been tiny in both scope and size, so writing out my error handling code by hand hasn’t been much of a hassle. However, I’ve been meaning to look into some of the popular error handling crates so I don’t have to write a ton of boilerplate every time I want to introduce a new type of error in my applications.
Nick Groenen covers two such crates in his blog post on error handling in Rust: https://nick.groenen.me/posts/rust-error-handling/
This reddit thread has further suggestions: https://www.reddit.com/r/rust/comments/gj8inf/rust_structuring_and_handling_errors_in_2020/
im is a library that implements immutable data structures for Rust. It works with serde so you can make your data persistent. Consider pairing this with Druid.
TIL that you can use Rust’s
Cow for representing a type that can either be borrowed or owned. This can be useful when you want to, for example, return either a static string (
&'static str) or a dynamically generated owned string (
String) from a function.
While reading Crafting Interpreters, I learned about something called the expression problem. It’s a problem I’ve run into countless times, especially in larger projects, but I never knew it had an actual name. As usual, Eli Bendersky has an in-depth article about the problem and its solution in C++ and Clojure.
After reading Eli’s article, I wondered how the problem would manifest in Rust and what the solution would be. Turns out it’s not too complicated. Want to add a new type? Just add it and implement all the traits you care about. Want to add a new operation? Define a new trait and implement it on all the types you care about. This article goes into more detail on what that looks like.