Day Nine - Rock-paper-scissors in Rust

Today I paired with Farid and Marc on rock-paper-scissors in Rust, which was extremely fun and satisfying! I should mention this is the first Rust code I’ve written from scratch.

Here’s our code, if you’re interested.

Things I learned in pairing

  • Named loops! I recall reading about this in the Rust book, but Marc pointed out a handy situation to use them.
  • Remember that loops also have scope.
  • Initializing an empty String, then using push_str() to push a string slice onto it. This is one way of dealing with the String vs. string slice issue.
  • Also using as_str() to deal with this issue, though I don’t feel clear on which contexts this is needed in. This also belongs on my list of things to learn more about below.
  • Using the pattern matching syntax to deal with conditions, which feels really concise and powerful!

Things I’m still struggling with

  • References and dereferencing in general
  • .expect() and .unwrap()
    • I’m doing some reading about the Result and Option types
  • I just need more finger exercise in this language

Please correct me if anything above seems not quite right!

Written on January 17, 2024