Step Into Labs

Step Into Rust · Lesson 11 · Systems Rust

FFI: Talking to C

extern blocks, C strings, callbacks into Rust, and wide strings for Windows.

Part of Step Into Rust. The full lesson, its missions and the real compiler and debugger are in the course. Try a free lesson first to see how it works.

Rust can call any function that uses the C calling convention. You declare it in an extern block, and every call is unsafe, because the compiler can't check what the C side does:

In this lesson

Missions

  1. Call C functions
  2. Owned C strings
  3. C calls Rust
  4. UTF-16 for Windows