Call Rust functions from C by using #[no_mangle] and pub extern "C" attributes, then compile as a static library and link with gcc.
You call Rust functions from C by marking the Rust function with #[no_mangle] and pub extern "C" to ensure C-compatible naming and calling conventions.
#[no_mangle]
pub extern "C" fn add(a: i32, b: i32) -> i32 {
a + b
}
Compile the Rust code as a static library using rustc --crate-type=lib and link it with your C program using gcc.
Calling Rust functions from C lets your C code run functions written in Rust. You must tell Rust to use C-style rules for naming and calling so C can find and use the function correctly. Think of it like translating a message so two people speaking different languages can understand each other.