有没有办法重命名货物项目?

时间:2017-07-04 18:25:25

标签: linux rust rust-cargo

我使用cargo new projectname --bin创建了一个项目。 如何将projectname更改为其他名称?

我查看了man pageCargo documentation。我也跑了:

  • cargo help
  • cargo --list
  • man cargo

在元数据文件(Cargo.toml,Cargo.lock,...)中,有“name”和“path”。我想我可以手动更改它们,但我不知道这是否会破坏任何东西。

最好的方法是什么?

2 个答案:

答案 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下,这是相当困难的事情:

  • 转到项目所在的目录,例如如果您的项目在名为rust的文件夹中名为hello_world,则转到rust文件夹 pi@raspberrypi:~/workspace/rust/hello_world $ cd ..
  • 从那里您可以通过以下方式重命名项目
    1. mv [项目的当前名称] [您想要的名称]移动。例如。如果我想将其从hello_world重命名为hello_rust,我会输入 mv hello_world/ hello_rust/重命名文件夹。
    2. 现在您只需要在Cargo.toml文件中更改名称:
      • pi@raspberrypi:~/workspace/rust $ cd hello_rust/
      • pi@raspberrypi:~/workspace/rust/hello_rust $ geany Cargo.toml
      • (我正在使用geany,但您可以使用任何喜欢的文本编辑器)
      • 在Cargo.toml中第二行更改
      • name = "hello_world"name = "hello_rust"

希望这将来可能对某人有所帮助