Rust Book, Chapter 5: Using Structs to Structure Related Data 0 ▲ Old man yells at Internet on Ross A. Baker (English) 22 hours ago · Tech · hide · 0 comments Chapter Five introduces Rust’s structs, which are similar to Scala’s case classes. Most of the differences come down to Rust’s borrow checking, mutability, and use of traits instead of inheritance from Java. The book club at $WORK got ahead and I fell behind. I’ll backfill Chapter Four later. Defining and instantiating structs # Rust structs are similar to Scala’s case classes: CC-BY-SA-4.0 struct User { active: bool, username: String, email: String, sign_in_count: u64, } CC-BY-SA-4.0 case class User( active: Boolean, username: String, email: String, signInCount: Long // signed ) Look past the u64 vs. Long and the snake_case vs. camelCase, and it’s the same idea: product types. The values of active, username, email, and sign_in_count are independent, so the number of possible users is the product of the possible values of each field. Field init shorthand # Rust has a shortcut for creating structs when the field name matches the value name. CC-BY-SA-4.0 fn build_user(email: String,… No comments yet. Log in to reply on the Fediverse. Comments will appear here.