mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2024-11-14 04:41:49 +08:00
Update ch19-01-unsafe-rust.md
This commit is contained in:
parent
d145b7a392
commit
41d483ee5f
@ -193,10 +193,7 @@ let slice = unsafe {
|
|||||||
|
|
||||||
#### 调用外部代码的`extern`函数是不安全的
|
#### 调用外部代码的`extern`函数是不安全的
|
||||||
|
|
||||||
有时, 你的Rust代码需要与其它语言交互. Rust有一个`extern`关键字可以实现这个功能, 这有助于创建并使用*外部功能接口(Foreign Function Interface)* (FFI). 例19-8 demonstrates how
|
有时, 你的Rust代码需要与其它语言交互. Rust有一个`extern`关键字可以实现这个功能, 这有助于创建并使用*外部功能接口(Foreign Function Interface)* (FFI). 例19-8演示了如何与定义在一个非Rust语言编写的外部库中的`some_function`进行交互. 在Rust中调用`extern`声明的代码块永远都是不安全的:
|
||||||
to set up an integration with a function named `some_function` defined in an
|
|
||||||
external library written in a language other than Rust. Functions declared
|
|
||||||
within `extern` blocks are always unsafe to call from Rust code:
|
|
||||||
|
|
||||||
<span class="filename">Filename: src/main.rs</span>
|
<span class="filename">Filename: src/main.rs</span>
|
||||||
|
|
||||||
@ -210,7 +207,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<span class="caption">Listing 19-8: Declaring and calling an `extern` function
|
<span class="caption">例19-8: Declaring and calling an `extern` function
|
||||||
defined in another language</span>
|
defined in another language</span>
|
||||||
|
|
||||||
Within the `extern "C"` block, we list the names and signatures of functions
|
Within the `extern "C"` block, we list the names and signatures of functions
|
||||||
|
Loading…
Reference in New Issue
Block a user