Jan :rust: :ferris: on Nostr: #Rust's module system is actually amazing! ✨ 🎡 Let's say we have a module `foo` ...
#Rust's module system is actually amazing! ✨ 🎡
Let's say we have a module `foo` that can create `Foo`s in different ways. Yes, that's it - it can only create `Foo`s.
But `Foo`s should also be able to `dance` and `twinkle`.
So we create two other modules `dance` and `twinkle` and `impl Foo` in each of them, so `Foo` can dance and twinkle.
But `Bar` can also dance - so we `impl Bar` in `dance` as well.
Do you see a pattern? You organize (primarily) by _behaviour_, not data.
#RustLang
Let's say we have a module `foo` that can create `Foo`s in different ways. Yes, that's it - it can only create `Foo`s.
But `Foo`s should also be able to `dance` and `twinkle`.
So we create two other modules `dance` and `twinkle` and `impl Foo` in each of them, so `Foo` can dance and twinkle.
But `Bar` can also dance - so we `impl Bar` in `dance` as well.
Do you see a pattern? You organize (primarily) by _behaviour_, not data.
#RustLang