4 ms·
>dynamic dispatch via trait objects over C structs What does this mean? A struct is just a block of memory with zero type information. So how does Rust do dyna
by aaaaaaaaaaab 8y ago
>dynamic dispatch via trait objects over C structs
What does this mean? A struct is just a block of memory with zero type information. So how does Rust do dynamic dispatch on C structs again?
- steveklabnik 8y agoI think what your parent is saying is that, since dynamic dispatch is created via a special kind of pointer in Rust (trait object), rather than embedding a vtable along with the data, Rust can dynamically dispatch to C structures where C++ can’t. Does that make any more sense? I can show some code later. I’m also not 100% sure that’s what your parent is saying.
- aaaaaaaaaaab 8y agoBut then it’s no longer a plain struct, rather a struct plus a pointer to the trait object. Which is perfectly doable in C++ too.
- steveklabnik 8y agoThe struct is a plain struct; just like an int is an int and a int* is a pointer, a struct is a struct and a trait object is a pointer. (It’s a double pointer: a pointer to that struct and a pointer to the vtable)