Rust API Bindings
In this series, I share intriguing problems I encountered in designing Rust API bindings for iOS and macOS and the rationale for my design choices in ensuring the API is idiomatic, correct, and performant in Rust.
-
Rust API Bindings: Core Foundation Signed/Unsigned Conversion
Handling
CFIndex
/usize
(signed/unsigned) conversion is important in crafting idiomatic Rust API bindings. I looked at how Apple handled this conversion between Core Foundation and Foundation, and between Foundation and Swift to help inform the direction for my Core Foundation crate. -
Rust API Bindings: Core Foundation Memory Management and Mutability
The design patterns used by Core Foundation for memory management and mutability fit surprisingly well in idiomatic Rust. This post shares an overview of how I reached this conclusion the hard way.
-
Rust API Bindings: CFStringGetBytes Is Hard, Part 1
Designing a "correct by default" interface for
CFStringGetBytes
is surprisingly complex, as many of its behaviors are encoding-dependent. -
Rust API Bindings: CFStringGetBytes Is Hard, Part 2
Using Rust’s features, we can provide API bindings to
CFStringGetBytes
that prevent unsupported argument combinations at the call site to fix the problems identified in the previous post.