logoalt Hacker News

scuff3dtoday at 3:53 PM1 replyview on HN

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.


Replies

reactordevtoday at 4:03 PM

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.

show 1 reply