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

你说的曾经没有我的故事 提交于 2020-06-03 16:13:10

问题


I have a front-end project that has a lot of stuff in src folder, and I have the opportunity to also use Rust on the server side. All my Rust server files are in the server folder; how can I tell Cargo to run ./server/app.rs?


回答1:


As stated in the comments, you are probably better off just moving all of your code into the "server" directory. If you don't, you are going to be swimming uphill against defaults, which is not usually a great idea.

That being said, you can 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"

See also:

  • Rust package with both a library and a binary?


来源:https://stackoverflow.com/questions/47649318/how-do-i-tell-cargo-to-run-files-from-a-directory-other-than-src

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!