Things I Learned While Building a CLI Tool in Rust (For Beginners)
Recently, I migrated an internal batch script from Python to Rust. I learned more than I expected, so here's a summary.
1. I struggled with ownership at first, but the compiler tells you everything anyway. The error messages are so helpful that I actually fixed things multiple times.
2. Managing state with structs + impl blocks feels natural. If you're coming from Java, you'll get used to it quickly.
3. The built-in support for cargo test is great when writing tests. It's more than enough without a separate framework.
4. Deployment is just dropping a single binary and you're done. The Docker image size also shrank dramatically.
I'm still a beginner with a lot of room to improve, but having only used scripting languages before, diving into a systems programming language really broadened my perspective. If you'd like to study together, feel free to leave a comment.
4 answers
Yeah, the most appealing part is that deployment is just a single binary. With Python, you'd have to set up a virtual environment and deal with all sorts of dependencies.
Ownership really feels like a wall at first, but once you get used to it, it actually makes you write safer code. When I started, I just did what the compiler told me, and patterns naturally emerged. For beginners, the best thing is to just start a small project and build the habit of reading error messages.
Well... I'm not sure it was necessary to port the internal batch scripts to Rust. Python is fast enough, and development is quicker. The ecosystem is much broader too. Rust is good, sure, but if you migrate just because 'everyone's using it,' it can make maintenance harder. Unless resources are a real bottleneck or binary distribution matters, I don't think the tradeoff is significant.
Oh, I hadn't thought about the deployment part—that's nice. I've been wanting to study Rust as well, so I'll refer to it.