- Cargo工具命令
- 构建和运行软件篋目录examples下文件
- Cargo项目构建命令
- Cargo项目测试特定代码命令
- 思考问题
- 类型
&str
和&'static str
有什么区别?
- 使用关键词use和extern有什么区别?
- 注解#[cfg(test)]有什么意义?
- 参考资料
# cargo build --example <目录examples下无扩展名的文件名称>
# cargo run --example <目录examples下无扩展名的文件名称>
cargo build --example i_hello
cargo run --example i_hello
cargo build
cargo build --release
cargo test tests::it_works_at_uint
cargo test test_hello_world
- 在语句里,它们是没有任何区别。
- 在函数返回类型里,它们是有区别的。
- 自Rust2018版本以来几乎不再需要extern语句。
- 关键词use方法与以前相同。
- 关键词use仅仅是引用标准符号的简写,或者使用trait时必须出现。
- 它告诉编译器在测试环境下进行编译,
- 仅当使用命令'cargo test'运行测试时,Cargo工具才会编译测试代码。