Rust 模块和依赖系统

Tags
rust
Created
Jun 2, 2019 7:21 AM

https://doc.rust-lang.org/nightly/edition-guide/rust-2018/module-system/path-clarity.html#changes-to-paths

// 同级模块引用:在项目中声明模块,使用 crate::xxx::xxx 来引用

mod:声明模块或者子模块

super:父模块

crate:当前 crate

extern // 2018 使用 cargo 可以忽略了,workspace 相对路径的依赖不能省略

use // use std::io::{self, Read}; 引入 io 以及 Read trait

pub use // reexport

cargo 默认使用 main.rs lib.rs 作为入口文件 // 两个同时存在?

mod 关键字可以定义模块,或者引入其他文件模块或者文件夹(查找 mod.rs)

库后缀 rlib(Rust 特定格式),cargo 构建库时生成文件名是 lib + 项目名

crate-type = ["dylib"] // 制定为标准动态库,是 c 能调用的必要条件

cargo 构建时会使用 Cargo.lock 中指定的依赖的版本 // 即第一次构建时安装的版本

cargo-workspaces

https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html

工作空间内的依赖使用 add_one = { path = "../add_one" }

SuperMade with Super