File tree Expand file tree Collapse file tree 3 files changed +14
-10
lines changed Expand file tree Collapse file tree 3 files changed +14
-10
lines changed Original file line number Diff line number Diff line change 1
1
# crate
2
2
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 才会被编译。
5
7
6
- crate 可以编译成二进制可执行文件(binary)或库文件(library)。默认情况下,` rustc ` 将从 crate 产生库文件。这种行为可以通过 ` rustc ` 的选项 ` --crate-type ` 覆盖。
8
+ crate 可以编译成二进制可执行文件(binary)或库文件(library)。默认情况
9
+ 下,` rustc ` 将从 crate 产生库文件。这种行为可以通过 ` rustc ` 的选项 ` --crate-type `
10
+ 重载。
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ $ ls lib*
24
24
library.rlib
25
25
```
26
26
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 ] 覆盖。
29
29
30
30
[ crate-name ] : ./attribute/crate.html
Original file line number Diff line number Diff line change 1
1
# ` extern crate `
2
2
3
- 链接一个 crate 到这个新库,必须使用 ` extern crate ` 声明。这不仅会链接库,还会导入与库名相同的模块里面的所有项。适用于模块的可见性规则也适用于库。
3
+ 要把上一节创建的库链接到一个 crate,必须使用 ` extern crate ` 声明。这不仅会
4
+ 链接库,还会用一个与库名相同的模块来存放库里面的所有项。于模块的可见性规则也
5
+ 适用于库。
4
6
5
7
``` rust,ignore
6
- // 链接到 `library`(库),导入 ` rary` 模块里面的项
8
+ // 链接到 `rary` 库,导入其中的项
7
9
extern crate rary;
8
10
9
11
fn main() {
@@ -17,9 +19,7 @@ fn main() {
17
19
```
18
20
19
21
``` 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 是已编译好的库的路径,这里假设它在同一目录下:
23
23
$ rustc executable.rs --extern rary=library.rlib && ./executable
24
24
called rary' s `public_function()`
25
25
called rary' s `indirect_access ()` , that
You can’t perform that action at this time.
0 commit comments