Comment by scuff3d
3 days ago
You can provide default method implementations for traits. Any type with that trait gets the default behavior, unless you override it.
3 days ago
You can provide default method implementations for traits. Any type with that trait gets the default behavior, unless you override it.
But that trait can’t have fields
You can use a struct that the other structs have as a field. The trait can then operate on that struct.
I'm not trying to convince you to use Rust. If you prefer C++ have at it. I was just trying to point out that most patterns in C++ have a fairly close analogy in Rust, just with different tradeoffs.
Yeah go has embedded structs. It’s ugly and allows one to address the fields on the parent and it exposes the struct (with the same fields) so it’s kind of a head scratcher.
To be honest, it’s been 3 years since I looked at rust and I might try again. I still prefer inheritance because some things just are-a thing. I also love ECS and components and see traits as that. I just wish I could store local state in those.
2 replies →