rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.79k stars 261 forks source link

Include brief explainer of C patterns and idioms in the FFI section #300

Open pie-flavor opened 3 years ago

pie-flavor commented 3 years ago

Ideally, the Nomicon should be enough to teach you everything you need to know about authoring an FFI API in Rust, without you needing to learn C to the level of knowing the idioms. Things like void *userdata, or having the return value be the error code with the 'real' return in an out-parameter, or when collections should be null-terminated instead of having a length parameter, or having a deallocation function and naming it _free. Right now the FFI chapter tells you how to link to another library, but not really how to write your own.