Instead of making a parent class that has a few key methods you need (e.g. send, recv) with the signatures (e.g. takes a pointer, returns a number), one can encode the use of those functions in a concept (e.g. a "socket" concept). This decouples the implementation from the use in the method, with the one big advantage being that it is easily testable -> no more need to carefully craft type hierarchies to carefully be able to substitute some mock object when you can just directly call it!
OO hierarchies certainly still have their place (even though so many conference talks seem to be about getting rid of them), but I'm glad I can relegate them to a dark corner of my toolbox until I absolutely need them.
In fact, come to think of it C++ concepts are basically Rust traits!
trait Test {
fn value(&self) -> i32;
}
impl dyn Test {
fn multiplied(&self) -> i32 {
self.value() * 2
}
}OO makes a lot of sense in hierarchic structures.
With that in mind, this pattern cleanly maps onto a trait with default implementations for methods plus several structs that implement the trait.
Performance-wise this is the same as a vtable generated by c++ and doesn't require creating more entities.