4 ms·
I think I have understood your examples: 1. In Rust, you can define a method on a trait object (a type that encloses a C struct), and then invoke it dynamicall
by ridiculous_fish 8y ago
I think I have understood your examples:
1. In Rust, you can define a method on a trait object (a type that encloses a C struct), and then invoke it dynamically with the syntactic appearance that 'self' is the struct. C++ does not allow you to add virtual methods to C structs.
2. In Rust, given a C struct T, you can convert T* to an Option<&T> without copying.
This stuff is all gravy but I wonder about the meat. Is there a good story for consuming C headers directly? C structs are typically a hash of typedefs and preprocessor gunk; can Rust navigate that?
- steveklabnik 8y agoThere’s a tool, bindgen, that can read in C headers (and limited C++ support, I believe) and produce the bindings Rust needs to understand them. It’s not perfect but IIRC it’s good enough for Firefox.