我如何告诉 Cargo 从 "src" 以外的目录中获取 运行 文件?

How do I tell Cargo to run files from a directory other than "src"?

我有一个前端项目,在 src 文件夹中有很多东西,我有机会在服务器端也使用 Rust。我所有的 Rust 服务器文件都在 server 文件夹中;我如何告诉 Cargo 到 运行 ./server/app.rs?

如评论中所述,您 可能 最好将所有代码移至 "server" 目录。如果你不这样做,你将违背默认设置向上游,这通常不是一个好主意。

也就是说,你 可以 specify the path to the binary or library in your Cargo.toml:

[[bin]]
name = "quux"
path = "server/main.rs"
[lib]
name = "quux"
path = "server/lib.rs"

另请参阅:

  • Rust package with both a library and a binary?