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”
  • freamon@endlesstalk.org
    link
    fedilink
    English
    arrow-up
    2
    ·
    9 months ago

    Thank you.

    I think there’s more to it though, in that simple values aren’t moved, they’re always copied (with any & in front indicating whether it’s the value to copy or the address)

    To illustrate:

    fn how_many(a: u32, fruit: String) {
        println!("there are {} {}", a, fruit);
    }
    
    
    fn main() {
        let a=4;
        let fruit = String::from("Apples");
        how_many(a, fruit);
    
        println!("the amount was {}", a);         // this works
        println!("the fruit was {}", fruit);      // this fails
    }
    
    

    The ‘a’ was copied, and the ‘fruit’ was moved.

    • JayjaderM
      link
      fedilink
      English
      arrow-up
      2
      ·
      9 months ago

      Correct! Values that can be copied are copied, and those that aren’t are moved.

      All primitive data types are copyable (or "are Copy ", which will make more sense once we get to Traits). I think arrays of primitives are as well? Most everything else isn’t by default.

      One of my favorite parts of Rust is that to make something copyable, you “just” implement the Copy trait for that thing.