rust - 我如何告诉 Cargo 构建 main.rs 以外的文件?

标签 rust rust-cargo

这是我的目录结构:

lowks@lowkster ~/src/rustlang/gettingrusty $ tree .
.
├── Cargo.lock
├── Cargo.toml
├── foo.txt
├── src
│   ├── boolean_example.rs
│   ├── function_goodbye_world.rs
│   ├── listdir.rs
│   ├── looping.rs
│   ├── main.rs
│   ├── pattern_match.rs
│   └── write_to_file.rs
└── target
    ├── build
    ├── deps
    ├── examples
    ├── gettingrusty
    └── native

6 directories, 11 files

当我运行“cargo build”时,它似乎只构建了 main.rs。我应该如何更改 Cargo.toml 以构建其余文件?

最佳答案

other.rs文件放入src文件夹的bin子文件夹中(./src/bin/other.rs)。并运行 cargo build --bin othercargo run --bin other

关于rust - 我如何告诉 Cargo 构建 main.rs 以外的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27613874/

相关文章:

rust - 我如何将 'pass down' 功能标志标记为 Cargo 中的子依赖项?

rust - 如何在 Rust 中运行单个文档测试?

rust - 无法释放文件。收到错误 : could not compile 'libc'

rust - 无法在 Mac m1 上遵循紫杉教程 - 使用未声明的类型 `Vec`

rust - 有没有办法自动为大量结构实现相同的功能?

rust - 无法在 Rust 中转换为超特征

module - 如何跨模块文件使用宏?

logging - 运行 cargo test 时如何设置日志级别?

types - HashMap 宏拒绝类型检查,失败并出现误导性(并且看似有缺陷)的错误消息?

python - 使用 ctypes 在 Python 中使用 Rust 返回的数组