知识卡片
依赖声明与导入分工
Cargo.toml 声明依赖后,Cargo 能解析并提供相应的 crates。代码仍须使用外部 crate 名作为路径入口,use 能缩短路径或让 trait 方法在当前作用域可用。std 由工具链提供,无须单独作为常规外部依赖声明。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 用包、crate 和模块管理增长中的项目 Using External Packages · 查看原书依据
Adding rand as a dependency in Cargo.toml tells Cargo to download the rand package and any dependencies from https://crates.io, and make rand available to our project.
参考来源
- 位置:《The Rust Programming Language(第2版)》第07章 用包、crate 和模块管理增长中的项目(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c07.xhtml`,块 0177)
- 结论依据:rand 依赖行的结果是下载并提供包,后续 Rust 路径才把具体项带入作用域。
- 原始内容:Adding rand as a dependency in Cargo.toml tells Cargo to download the rand package and any dependencies from https://crates.io, and make rand available to our project.