|
|
|
|
|
by conradludgate
1703 days ago
|
|
Other than enums, there is another way to achieve a sort of polymorphism in Rust similar to how it's used in that compiler book. You can use Traits to encapsulate an idea and implement them on Structs. You can then use `dyn Trait` to represent a type erased dynamic instance of that trait (similar to how abstract class instances are represented). This has some benefits in libraries, allowing external parties ability to implement their own instances of traits, but in a compiler where you will implement all possibilities, its not as useful. You also lose the ability to match on variants (instead having to resort to downcasting) |
|