Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Best practices to design a C API that can be ergonomically used in Rust
Hi,
For those of you who have worked on safe Rust bindings to C libraries before, what aspects of a C API makes it particularly suitable to be used in Rust.
Or in other words, what to do and what to avoid when designing a C API with the express purpose to be used within Rust.
Here are the things I came up with, but I suspect there are other things that I am forgetting.
All types on the FFI API surface should fall into one of the two categories:
This kind of type manages (allocates and frees) a resource like memory or other system resources.
These types should should have straightforward object lifetimes and the C API should expose the following functions:
new
methoddrop
methodShould be representable as a opaque types, only work on raw pointers (which are wrapped by safe abstraction)
In your experience, what other parts should be considered, that are otherwise annoying (not ergonomic) or difficult to represent in Rust?
1 post - 1 participant
🏷️ Rust_feed