From bfbadf35e89acbfde9e40076bf0442b6ded4c66d Mon Sep 17 00:00:00 2001 From: letaldev <120847863+lipx1508@users.noreply.github.com> Date: Tue, 13 Oct 2026 00:43:04 +0000 Subject: [PATCH] Replace cty:: with core::ffi:: As of Rust 1.64, the crate cty is no longer needed for C types --- src/interoperability/c-with-rust.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/interoperability/c-with-rust.md b/src/interoperability/c-with-rust.md index 74ec868b..d457f82a 100644 --- a/src/interoperability/c-with-rust.md +++ b/src/interoperability/c-with-rust.md @@ -33,14 +33,14 @@ When translated to Rust, this interface would look as such: /* File: cool_bindings.rs */ #[repr(C)] pub struct CoolStruct { - pub x: cty::c_int, - pub y: cty::c_int, + pub x: core::ffi::c_int, + pub y: core::ffi::c_int, } extern "C" { pub fn cool_function( - i: cty::c_int, - c: cty::c_char, + i: core::ffi::c_int, + c: core::ffi::c_char, cs: *mut CoolStruct ); } @@ -56,8 +56,8 @@ pub struct CoolStruct { ... } By default, Rust does not guarantee order, padding, or the size of data included in a `struct`. In order to guarantee compatibility with C code, we include the `#[repr(C)]` attribute, which instructs the Rust compiler to always use the same rules C does for organizing data within a struct. ```rust,ignore -pub x: cty::c_int, -pub y: cty::c_int, +pub x: core::ffi::c_int, +pub y: core::ffi::c_int, ``` Due to the flexibility of how C or C++ defines an `int` or `char`, it is recommended to use primitive data types defined in `cty`, which will map types from C to types in Rust. @@ -69,8 +69,8 @@ extern "C" { pub fn cool_function( ... ); } This statement defines the signature of a function that uses the C ABI, called `cool_function`. By defining the signature without defining the body of the function, the definition of this function will need to be provided elsewhere, or linked into the final library or binary from a static library. ```rust,ignore - i: cty::c_int, - c: cty::c_char, + i: core::ffi::c_int, + c: core::ffi::c_char, cs: *mut CoolStruct ```