Rust Programming - No Inheritance

400,744
0
Published 2022-11-02
See the full video at ➜➜    • How does Rust make me write GOOD CODE ?  

Help support this channel: patreon.com/jeremychone

Rust Programming has no inheritance, but it is for the better. Checkout the full Top 5 Reasons How Rust Programming make us write good code:    • How does Rust make me write GOOD CODE ?  

Jeremy Chone:

- Twitter - twitter.com/jeremychone
- Discord On Rust - discord.gg/W2besKCzjx
- AWESOME-APP - awesomeapp.dev/ - Rust Templates for building awesome applications.
- Patreon - patreon.com/jeremychone - Any help is a big help (for Rust educational content)

Other popular Rust Programming videos:

- AWESOME-APP Full Overview - Rust template for building Awesome Desktop Application:    • Building Awesome Desktop App with Rus...  
- Tauri Quick Introduction (Desktop App wit Rust Programming):    • Rust Tauri 1.0 - Quick Intro - Rust D...  
- Rust Web App tutorials series:    • Rust Web App - 1/3 - Data Access  
- Rust Bevy Full Tutorial - Game Development with Rust:    • Rust Bevy Full Tutorial - Game Develo...  
- Rust for Java Developers series:    • Rust for Java Developers 1/3 - Introd...  

Playlists:

- Rust For Desktop App:    • Rust Programming for Desktop App  
- Everything Rust Programming - Tutorials, Courses, Tips, Examples:    • Everything Rust Programming - Tutoria...  
- Rust Programming for Web Development:    • Rust Programming for Web Development  
- Rust Courses:    • Rust Course 2021 by the book | RustLang  
- Furst for Java Developers:    • Rust for Java Developers  

All Comments (21)
  • @okie9025
    OOP: everything is a class Rust: everything is an algebraic data type
  • @motbus3
    One common misconception is that OO needs to be embedded in the language. You can model your entities with classes and implement without it. We just got used to have the full set
  • @G11713
    You can also implement common behavior on the `enum` type itself using a `match` statement to provide specific responses.
  • @orange1304
    Cold shower everyone needs: There's nothing new after the Lisp.
  • @shofr8475
    You can simply make a trait and implement it to the enum instead of each struct
  • My life long dream of typing Floor(Floor) is finally possible 😎, Poggers
  • @filcondrat
    that reminds me of type classes in Haskell
  • don't really need an enum. could use a marker trait or use the trait itself
  • @Cptcat.
    that looks simple and easier to implement polymorphism.
  • @Lord2225
    You can additionally use DeRef trait if you want all methods and fields from composed struct. It is handy if you want to build extension for other struct but still use it as before without outer.inner syntax.
  • Interestingly, this is similar to some of the ideas I put forward in my PhD dissertation in 2010.
  • It's very nice, I remember in some of my old game projects I would have several levels of inheritance, and hurts my eyes to look at that now. Then I started using interfaces more it was just more dynamic and allowed for better generic code. I feel like this works very similar to that, but more modular and just cleaner.
  • @TheOrioNation
    The problem I see most people coming from OO languages have with Rust is trying to shoehorn patterns intended to solve shortcomings of OOP, especially aspects of data modeling, and come to the conclusion that Rust isn't suited for such tasks. Rust is plenty powerful and easy to work with once you stop thinking in classes. Traits are not interfaces.
  • @edhofiko7624
    i dont know about other, but i really like to call this programming paradigm of semi OOP with trait but no inheritance as Polymorphic Programming.
  • Is there any way to force all structs in the enum to have a trait implemented? So that if it gets removed from any of the structs, I can get a compile error.
  • @licks4vr
    This literally just helped me build my rust program successfully
  • I think there should be a way to auto implement a trait for the whole enum when all containing types implement the trait. Bsp: Dog, duck, and cat implement noise. Then there should be a way to simply 1 line implement the trait for animal instead of needing a match that forwards the method to the individual versions.
  • Inheritance means you can define an "Animal" struct and all animals(including pets) inherit eat, sleep and reproduce methods.
  • There's "behaviour inheritance", which is used for regular inheritance but in a controlled manner.