Skip to content

Commit b1865ae

Browse files
authored
Merge pull request #35 from AmaiKinono/fix/chapter11
修正原第十章 / 现第十一章
2 parents 5414dc1 + f4145b8 commit b1865ae

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/crates.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# crate
22

3-
crate(中文有“包,包装箱”之意)是 Rust 中的编译单元。不管什么时候调用 `rustc some_file.rs``some_file.rs` 都被当作 **crate 文件**。如果 `some_file.rs` 里面含有 `mod` 声明,那么模块文件的内容将在运行编译器之前与 crate 文件合并。换句话说, 模块**不会**单独进行编译,只有 crate 文件进行了编译(英文:modules
4-
do *not* get compiled individually, only crates get compiled)。
3+
crate(中文有 “包,包装箱” 之意)是 Rust 的编译单元。当调用 `rustc some_file.rs`
4+
时,`some_file.rs` 被当作 **crate 文件**。如果 `some_file.rs` 里面含有 `mod`
5+
声明,那么模块文件的内容将在编译之前被插入 crate 文件的相应声明处。换句话说,模
6+
**不会**单独被编译,只有 crate 才会被编译。
57

6-
crate 可以编译成二进制可执行文件(binary)或库文件(library)。默认情况下,`rustc` 将从 crate 产生库文件。这种行为可以通过 `rustc` 的选项 `--crate-type` 覆盖。
8+
crate 可以编译成二进制可执行文件(binary)或库文件(library)。默认情况
9+
下,`rustc` 将从 crate 产生库文件。这种行为可以通过 `rustc` 的选项 `--crate-type`
10+
重载。

src/crates/lib.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $ ls lib*
2424
library.rlib
2525
```
2626

27-
库的前缀为 “lib”,默认情况下它们跟随着 crate 文件命名(原文:by default they get named after their
28-
crate file),但此默认名称可以使用 [`crate_name` 属性][crate-name] 覆盖。
27+
默认情况下,库会使用 crate 文件的名字,前面加上 “lib” 前缀,但这个默认名称可以
28+
使用 [`crate_name` 属性][crate-name] 覆盖。
2929

3030
[crate-name]: ./attribute/crate.html

src/crates/link.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# `extern crate`
22

3-
链接一个 crate 到这个新库,必须使用 `extern crate` 声明。这不仅会链接库,还会导入与库名相同的模块里面的所有项。适用于模块的可见性规则也适用于库。
3+
要把上一节创建的库链接到一个 crate,必须使用 `extern crate` 声明。这不仅会
4+
链接库,还会用一个与库名相同的模块来存放库里面的所有项。于模块的可见性规则也
5+
适用于库。
46

57
```rust,ignore
6-
// 链接到 `library`(库),导入 `rary` 模块里面的项
8+
// 链接到 `rary` 库,导入其中的项
79
extern crate rary;
810
911
fn main() {
@@ -17,9 +19,7 @@ fn main() {
1719
```
1820

1921
```bash
20-
# library.rlib 是已编译好的库的路径,假设在这里它在同一目录下:
21-
# (原文:Where library.rlib is the path to to the compiled library,
22-
# assumed that it's in the same directory here:)
22+
# library.rlib 是已编译好的库的路径,这里假设它在同一目录下:
2323
$ rustc executable.rs --extern rary=library.rlib && ./executable
2424
called rary's `public_function()`
2525
called rary's `indirect_access()`, that

0 commit comments

Comments
 (0)