657

August 23rd, 2023 × #Rust#JavaScript#Web Development

Rust for JS Devs — Part 2

In part 2 of Rust for JavaScript developers, Scott and Wes dive deeper into Rust's type system, talking about integer types, strings, string slices, arrays, tuples, and other collection types. They also cover defining structs, adding methods, and other fundamentals.

or

In this episode of Syntax, Wes and Scott jump into part 2 of their look at Rust for JavaScript developers, including variables in Rust, type systems in Rust, signed and unsigned integers, and more.

Show Notes

let x = 5;  // x is immutable
let mut x = 5; // x is mutable
const MAX_POINTS: u32 = 100_000; // must be defined at compile time
  • 10:42 Type System in Rust
  • 15:52 Types in Rust
  • 19:06 Why does Rust have signed and unsigned integers?
  • 23:35 Slicing strings with &str
  • 27:35 enum
  • 27:55 struct
  • 28:19 Vec
  • 29:33 HashMap and HashSet
  • 33:00 Converting Signed to Unsigned Numbers
let unsigned_value: u8 = 200;
let signed_value: i8 = unsigned_value as i8;
  • 36:12 What’s up with &str?
  • 43:31 Rust error messages
  • 45:28 What is a Struct?
struct User {
   username: String,
    email: String,
    sign_in_count: u64,
    active: bool,
}

// You can create an instance of a struct like this:
let user1 = User {
    email: String::from("[email protected]"),
    username: String::from("someusername123"),
    active: true,
    sign_in_count: 1,
};

impl User {
    fn login(&mut self) {
        self.login_count += 1;
    }
}
  • 49:17 SIIIIICK ××× PIIIICKS ×××

××× SIIIIICK ××× PIIIICKS ×××

Shameless Plugs

Tweet us your tasty treats

Share

Play / pause the audio
Minimize / expand the player
Mute / unmute the audio
Seek backward 30 seconds
Seek forward 30 seconds
Increase playback rate
Decrease playback rate
Show / hide this window