Update extern docs for Rust 2024 and add safety remarks

This commit is contained in:
Tobias
2025-04-23 20:33:22 +02:00
parent e3e432d4d6
commit 1862feb0e7

View File

@@ -381,11 +381,15 @@ mod enum_keyword {}
/// lazy_static;`. The other use is in foreign function interfaces (FFI). /// lazy_static;`. The other use is in foreign function interfaces (FFI).
/// ///
/// `extern` is used in two different contexts within FFI. The first is in the form of external /// `extern` is used in two different contexts within FFI. The first is in the form of external
/// blocks, for declaring function interfaces that Rust code can call foreign code by. /// blocks, for declaring function interfaces that Rust code can call foreign code by. This use
/// of `extern` is unsafe, since we are asserting to the compiler that all function declarations
/// are correct. If they are not, using these items may lead to undefined behavior.
/// ///
/// ```rust ignore /// ```rust ignore
/// // SAFETY: The function declarations given below are in
/// // line with the header files of `my_c_library`.
/// #[link(name = "my_c_library")] /// #[link(name = "my_c_library")]
/// extern "C" { /// unsafe extern "C" {
/// fn my_c_function(x: i32) -> bool; /// fn my_c_function(x: i32) -> bool;
/// } /// }
/// ``` /// ```