Finally, we can make our own types (or data structures)!!


This is supplementary/separate from the Twitch Streams (see sidebar for links), intended for discussion here on lemmy.

The idea being, now that both twitch streams have read Chapters 5 and 6, we can have a discussion here and those from the twitch streams can have a retrospective or re-cap on the topic.

This will be a regular occurrence for each discrete set of topics coming out of The Book as the twitch streams cover them


With Ch 4 on the borrow checker out of the way, chapters 5 & 6 feel like the “inflection point” … the point where we’re ready to actually start programming in rust.

Custom types, data structures, objects with methods, pattern matching, and even dipping into rust’s traits system and it’s quasi answer to class inheritance.

If you’re comfortable enough with the borrow checker, you can really start to program with rust now!


I personally didn’t think this content was difficult, though it prompts some interesting points and topics (which I’ll mention in my own comment below).

  • Any thoughts, difficulties or confusions?
  • Any quizzes stump you?
  • Any major tips or rules of thumb you’ve taken away or generally have about using structs and enums?
  • maegul (he/they)@lemmy.mlOPM
    link
    fedilink
    English
    arrow-up
    1
    ·
    6 months ago

    Also, on the topic of “having references as fields in structs” … see this conversation we had here about that.

    That conversation started from a post on the users . rust-lang forum, where the ultimate pithy and harsh conclusion about doing this was:

    You’re not allowed to use references in structs until you think Rust is easy. They’re the evil-hardmode of Rust that will ruin your day.

    😉

    Use Box or Arc to store things in structs “by reference”. Temporary borrows don’t do what you think they do.