RustForeign Function Interface (FFI)


  • #[link(name = "snappy")] // the foreign library to be linked to (optional)

    extern { ... } // list of function signatures in the foreign library

Calling libc function from nightly rust

The libc crate is 'feature gated' and can only be accessed on nightly Rust versions until it is considered stable.

extern crate libc;
use libc::pid_t;

#[link(name = "c")]
extern {
    fn getpid() -> pid_t;

fn main() {
    let x = unsafe { getpid() };
    println!("Process PID is {}", x);