Back to Browse

🔍 Code With Me in Rust: Tuples, Structs, and Traits

235 views
Jun 1, 2025
47:52

Continuing in my exploration of Rust. This time, I'm playing with how we store information. These are the goals of what I build: - Using a tuple to represent a cylinder - Comparing that with using a struct to represent a cylinder - Using impl to add methods to structs so now we can make our structs do things. They feel a little bit like objects without inheritance - Using traits to achieve polymorphism - I create a Shape trait and make Cylinder and Cube implement it so I can have a vector of shapes and print out their volumes Along the way, we learn about moving structs as opposed to copying the pointer to a struct and the difference between &str and String. This session is ideal for developers familiar with other languages who are curious about Rust's unique features and syntax. 🔗 Resources: A Gentle Introduction to Rust: https://stevedonovan.github.io/rust-gentle-intro/ Rust By Example - Vectors: https://doc.rust-lang.org/rust-by-example/std/vec.html 📌 Chapters: 00:00 Introduction 01:18 A tuple to hold a cylinder 03:22 Passing a tuple into a function 07:17 Tuple summary 07:48 A struct to hold a cylinder 10:57 Adding tests to our struct 14:15 Creating a new cylinder from an existing one 17:58 "move" vs. "copy" 44:00 Difference between &str and String 23:12 Using the Cylinder struct 24:36 Using things declared in another file 27:26 Attaching methods to structs and &self 26:47 Passing a struct into a function 34:42 Creating a Shape trait 40:00 Putting both kinds of shapes into a vector 42:00 Add another method to the trait for practice 44:00 String vs &str 47:30 Conclusion Don't forget to like, subscribe, and hit the bell icon for more programming explorations! 👍 If this helped you think like a developer, hit like, subscribe, and tap that bell 🔔 so you don’t miss the next part! CHECK OUT MY OTHER VIDEOS: Rust Programming Playlist: https://www.youtube.com/playlist?list=PLZLC5AM_r9AjYwkudkKvO0yHX3zv3sDV2 C Programming Playlist: https://www.youtube.com/playlist?list=PLZLC5AM_r9Ag0CZdGTUm3FWhBDX28B0Dj Intro to Java Playlist: https://www.youtube.com/playlist?list=PLZLC5AM_r9Ajo6LH_-g7dXjZemaQ5QXnV Software Engineering Topics Playlist: https://www.youtube.com/playlist?list=PLZLC5AM_r9AgMHq42vUXHkXEws3JWdnDb

Download

0 formats

No download links available.

🔍 Code With Me in Rust: Tuples, Structs, and Traits | NatokHD