Hi All! Welcome to the Reading Club for Rust’s “The Book” (“The Rust Programming Language”). This is week 1 (the beginning!!).

Have a shot at going through “the reading” and post any thoughts, confusions or insights here

“The Reading”

The Twitch Stream

What’s Next Week?

  • Chapters 3 and 4
  • Start thinking about challenges or puzzles to try as we go in order to get some applied practice!
    • EG, Advent of Code
    • Maybe some basic/toy web apps such as a “todo”
  • nmtake@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    5 months ago

    The Enum Ordering provides compile-time safety. For example, if cmp() takes a string or int, the compiler can’t catch invalid inputs (“less”, “equal”, -123, …) at compile time and crash at runtime.

    • maegul@lemmy.mlOPM
      link
      fedilink
      English
      arrow-up
      2
      ·
      5 months ago

      Hmm, not sure I’m entirely with you.

      If the argument to cmp is of an incorrect or incompatible type (where AFAIU the parent object and argument have to be the same type, eg u32), that alone will be surfaced at compile time no?

      If so, then Ordering is actually relatively trivial. It’s an enum, with variants for each possible outcome of a comparison on orderable variables (eg numbers).

      And the output of cmp is an Ordering type, which is nice for match statements, as, AFAIU, it forces us to address all possible scenarios (each being a variant of the Ordering enum).

      But the compile time safety will come from basic type checking on the argument to cmp.

      Am I off base here?

      • nmtake@lemm.ee
        link
        fedilink
        English
        arrow-up
        2
        ·
        5 months ago

        Oh I was completely wrong. cmp() takes a number (not Ordering) and returns Ordering. Sorry for bothering you.

        • maegul@lemmy.mlOPM
          link
          fedilink
          English
          arrow-up
          2
          ·
          5 months ago

          Pretty sure that’s what this is all about! A safe space to work through the ideas and details without worrying about being wrong. I wouldn’t have understood this better if you didn’t “bother” me and now we (and anyone else reading this presumably) are both better off!