:: krowemoh

Saturday | 28 DEC 2024
Posts Links Other About Now

previous
next

Programming Rust - 01

2022-03-31

The book has come in! Programming Rust by Jim Blandy, Jason Orendorff and Leonora F.S. Tindall. Let's see how much I get through. No promises, it could just be the first page :)

The first step was installing rustup and I'm going to use my WSL2 Ubuntu. The only pain here was adding $HOME/.cargo/bin to my fish config file to get access to the rust commands. I wonder if there's a way to automate this where the rustup script checks which shell you're running and it will inject it in. There probably is a good reason for why it doesn't do that but does for bash. Once I got rust install, I created a new cargo project and everything looks to be compiling.

Time to open the book!

Interesting definition of systems programming as resource constrained programming. This is maybe why I want to learn rust, in my day job memory, cpu and storage is all basically infinite.

The opening of the chapter goes into undefined behavior and corrupting the call stack. Also mentions that struxnet used a bug in the true type parser in word processors to do its job. That's pretty cool. Safety and concurrency! Let's see where it takes me.

Something I learned in the first section was that return is reserved for early returns and that the idiomatic way of returning in rust is to simply have the expression at the end without a semicolon.

I can also write #[test] on top of a function and then run those functions with cargo test. That's pretty useful to know and definitely would have helped in other projects.

I really like the gcd example as it goes over many ideas like looping, throwing errors, references and dereferencing. I'm still on the first 10 pages! I'm going to have to start reading faster and only implement the parts that I care about to speed this up.