Luca Aurelia
luca-aurelia.bsky.social
Luca Aurelia
@luca-aurelia.bsky.social
There are situations where this doesn't work, like if you need a Vec that contains both Cats and Dogs, but for some cases it works great and doesn't require anything special at all.
April 17, 2025 at 3:04 PM
Cat and Dog are both distinct types. They don't implement an Animal trait or anything. They just "happen" to have a method called `make_sound()` with the same signature, so when I sub one for the other, no code needs to change.
April 17, 2025 at 3:04 PM
So excited for this! Another big idea for me coming from OOP languages was "syntactic polymorphism." What I mean is:

```
let animal: Cat = Cat::new();
animal.make_sound();
```

If later, I realize I need a Dog instead of a Cat:

```
let animal: Dog = Dog::new();
animal.make_sound();
```
April 17, 2025 at 3:04 PM