[][src]Module show_notes::e031

FFI Deep Dive

Show Notes

It's impossible to make the declarations below follow the order I talked through them on the recording without also making them horrible to read, so just use this outline instead:

  1. add_in_rust
  2. Strings
    1. concat_strings
    2. free_rust_string
  3. Point
    1. point_translate
  4. union
  5. OpaquePoint
    1. opaque_point_new
    2. opaque_point_translate
    3. opaque_point_free

Sponsors

Thanks to Parity for sponsoring the show and hiring Rust developers!

Patreon Sponsors

(Thanks to the couple people donating who opted out of the reward tier, as well. You know who you are!)

Become a sponsor

Contact

Modules

unions

Demonstrate unions! Combines an enum and a union into a struct that acts mostly like a regular Rust enum.

Structs

OpaquePoint

A struct identical to Point, but which is not #[repr(C)]!

Point

A simple struct which we can expose to a C API. Note that it is #[repr(C)]!

Script

e031: FFI Deep Dive!

Functions

add_in_rust

The simplest possible example of exposing Rust functions via a C FFI.

concat_strings

Take two strings in and concatentate them without mutating either.

free_rust_string

Free any string allocated by Rust.

opaque_point_describe
opaque_point_free

Safely drops the OpaquePoint instance.

opaque_point_new
opaque_point_translate

Expose an interface for C API callers to call the OpaquePoint impl.

point_translate

Expose an interface for C API callers to call the Point impl.