Module ffi

Utilities related to FFI bindings.

This module provides utilities to handle data across non-Rust interfaces, like other programming languages and the underlying operating system. It is mainly of use for FFI (Foreign Function Interface) bindings and code that needs to exchange C-like strings with other languages.

Overview

Rust represents owned strings with the String type, and borrowed slices of strings with the str primitive. Both are always in UTF-8 encoding, and may contain nul bytes in the middle, i.e., if you look at the bytes that make up the string, there may be a \0 among them. Both String and str store their length explicitly; there are no nul terminators at the end of strings like in C.

C strings are different from Rust strings:

Representations of non-Rust strings

CString and CStr are useful when you need to transfer UTF-8 strings to and from languages with a C ABI, like Python.

Modules