我使用cargo new projectname --bin
创建了一个项目。
如何将projectname
更改为其他名称?
我查看了man page和Cargo documentation。我也跑了:
cargo help
cargo --list
man cargo
在元数据文件(Cargo.toml,Cargo.lock,...)中,有“name”和“path”。我想我可以手动更改它们,但我不知道这是否会破坏任何东西。
最好的方法是什么?
答案 0 :(得分:7)
我认为您应该手动更改它。真的不那么难。
我运行此代码:
$ cargo new smurf --bin
Created binary (application) `smurf` project
$ cd smurf/
smurf$ cargo build
....
smurf$ grep -rl smurf .
./target/debug/smurf.d
./target/debug/smurf
./target/debug/.fingerprint/smurf-35f069edf7faaa12/bin-smurf-35f069edf7faaa12.json
./target/debug/.fingerprint/smurf-35f069edf7faaa12/dep-bin-smurf-35f069edf7faaa12
./target/debug/deps/smurf-35f069edf7faaa12
./Cargo.lock
./Cargo.toml
从所有这些文件中,可能只删除整个target
。也可以删除.lock
文件。而Cargo.toml
......你可以编辑它。
我尝试只更改Cargo.toml
,而且只是改编。但是你最终会在target
中找到无用的文件,所以我建议你删除它们。
答案 1 :(得分:0)
在Linux下,这是相当困难的事情:
pi@raspberrypi:~/workspace/rust/hello_world $ cd ..
mv hello_world/ hello_rust/
重命名文件夹。pi@raspberrypi:~/workspace/rust $ cd hello_rust/
pi@raspberrypi:~/workspace/rust/hello_rust $ geany Cargo.toml
name = "hello_world"
至name = "hello_rust"
希望这将来可能对某人有所帮助