Getting Rusty: Day 2

2017-09-15 in github, rust

Notes about my second combined full day's worth of Rust, spanning... more than a single day. I implemented github's webhook verification, which turned out challenging due to mismatched hash outputs and needing to convert from a hex string to the equivalent bytes. You can click through to today's version of code.

It turns out FromHex used to be publicly part of Rust, but when serialization was moved to Serde it was made private. This would be fine - we can just add Serde! - except Serde didn't re-implement the trait, so we're left with no real suitable alternative. I could have used Rust's internal implementation with the #![feature(rustc_private)], but that requires nightly, and I'm sticking to stable so I can focus on learning Rust without getting tempted by shiny/maybe-buggy new features. I ended up just copy-pasting the internal code into its own file, and using it as if it were still an external function.

Notes

  • understanding ownership

    • preventing classes of errors at compile time by the type system is cool
    • not sure what the lifetime of a borrow attaches to besides 'scope'
    • shows implicit syntax for borrows, I wish they showed a brief "this is the equivalent explicit syntax" to make understanding the auto-generated docs easier
  • structs

    • the data part of a class
    • classes are structs + a bunch of trait implementations to compose a class from parts ()
    • struct update syntax is cool, like ESwhatever's object spread syntax, except two dots instead of three (which I will forget)
    • it's the I in SOLID
  • modules

    • seems pretty standard
    • overloading of the mod keyword is unfortunate
    • I like the private by default setup
  • collections

    • 👍
    • hash_map literal construction would be nice, seems like it would be doable as a macro maybe
  • error handling

    • skimmed mostly, will probably come back to it
  • traits

    • love composing types, traits are really cool
  • lifetimes

    • too tired to understand this, need to wait for the weekend