unsafe extern 块

版本新特性 / Rust 2024

// *** before: ***
extern "C" {
    fn abs(input: i32) -> i32;
}

// *** in version Rust 2024: ***
// declaring a foreign function is a promise to the compiler, and unsafe
unsafe extern "C" {
    fn abs(input: i32) -> i32;        // call it inside unsafe only
    safe fn sqrt(x: f64) -> f64;      // and this one is marked safe
}