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

Dav*_*ela 3 linux rust rust-cargo

我创建了一个项目:cargo new projectname --bin.我如何更改projectname为其他名称?

我检查了手册页Cargo文档.我也跑了:

  • cargo help
  • cargo --list
  • man cargo

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

最好的方法是什么?

rod*_*igo 8

我认为你应该手动更改它.真的不是那么难.

我运行这段代码:

$ 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
Run Code Online (Sandbox Code Playgroud)

从所有这些文件中,target可以删除整个文件.该.lock文件也可以删除.而且Cargo.toml......你可以编辑它.

我尝试只更改Cargo.toml所有正常工作.但是你最终得到了无用的文件,target所以我建议你删除它们.

  • Cargo clean 将删除整个目标目录。请参阅:https://doc.rust-lang.org/cargo/commands/cargo-clean.html (3认同)

小智 5

在 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"

希望这可以帮助将来的人