gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 07:44:44 25 4
gpt4 key购买 nike

这是我的目录结构:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com