Creating C-structs from Rust

Now, how do we call these functions from Rust? Moreover, how do we create instances of mars_t or insn_t? Well, recall back in Chapter 03, The Rust Memory Model – Ownership, References, and Manipulation, that Rust allows control over memory layout in structures. Specifically, all Rust structures are implicitly repr(Rust), types aligned to byte boundaries with structure fields being reordered as the compiler sees fit, among other details. We also noted the existence of a repr(C) for structures, in which Rust would lay out a structure's memory representation in the same manner as C. That knowledge now comes to bear.

What we will do is this. First, we'll compile our C code as a library and rig it to link into feruscore. ...

Get Hands-On Concurrency with Rust now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.