-
Notifications
You must be signed in to change notification settings - Fork 192
[WIP] Adding C interop sections #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
on transforming data between the two languages. | ||
For this purposes there are two dedicated modules | ||
in the `stdlib` called `std::ffi` and `std::raw`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan to elaborate more on what ffi and raw do?
Thanks for starting this. I left a little inline comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff. I left a few comments but this is a great start and good stuff in general.
We'll definitely want to link back to the FFI portion of the Rustonomicon which has some great content: https://doc.rust-lang.org/nomicon/ffi.html
src/interoperability/rust-with-c.md
Outdated
### `extern "C"` | ||
|
||
By default, any function you write in Rust will use the | ||
Rust ABI (which is also no stabilised). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sp: also not stabilized.
on transforming data between the two languages. | ||
For this purposes there are two dedicated modules | ||
in the `stdlib` called `std::ffi` and `std::raw`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making these hyperlinks to the docs would probably be handy.
| etc | ... | ... | | ||
|
||
Primitive types can simply be cast to Rust types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of "cast" the wording "converted into" would be more appropriate for the example shown. In this case, c_uint
and u32
end up being the same type but that won't always be the case.
Just thinking the audience might react negatively to the idea of a "cast" being required (which often implies unsafety).
Apologies for the long delay before getting back to this! I fixed the marked sections in the existing text, but I'll try to finish the rest of it by the end of the week! |
45: First pass at "C with Rust" r=ryankurte a=jamesmunns Took a first pass at this, I feel like there are probably a few places where I could use more/better examples or links to external information. Please feel free to review and suggest changes. Companion to @spacekookie's work in #23. Co-authored-by: James Munns <james.munns@ferrous-systems.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @spacekookie!
bors r+
23: [WIP] Adding C interop sections r=jamesmunns a=spacekookie *This is still WIP, missing a bunch of stuff.* This PR adds sections to the book about how to embed Rust code into C/C++ projects and how to interact between Rust and C, transforming data into the appropriate formats. Co-authored-by: Katharina Fey <kookie@spacekookie.de> Co-authored-by: James Munns <james.munns@ferrous-systems.com> Co-authored-by: Katharina <kookie@spacekookie.de>
Build succeeded |
45: First pass at "C with Rust" r=ryankurte a=jamesmunns Took a first pass at this, I feel like there are probably a few places where I could use more/better examples or links to external information. Please feel free to review and suggest changes. Companion to @spacekookie's work in rust-embedded#23. Co-authored-by: James Munns <james.munns@ferrous-systems.com>
23: [WIP] Adding C interop sections r=jamesmunns a=spacekookie *This is still WIP, missing a bunch of stuff.* This PR adds sections to the book about how to embed Rust code into C/C++ projects and how to interact between Rust and C, transforming data into the appropriate formats. Co-authored-by: Katharina Fey <kookie@spacekookie.de> Co-authored-by: James Munns <james.munns@ferrous-systems.com> Co-authored-by: Katharina <kookie@spacekookie.de>
This is still WIP, missing a bunch of stuff.
This PR adds sections to the book about how to embed Rust code into C/C++ projects and how to interact between Rust and C, transforming data into the appropriate formats.