簡體   English   中英

有沒有辦法重命名 Cargo 項目?

[英]Is there any way to rename a Cargo project?

我使用以下方法創建了一個項目: cargo new projectname --bin 如何更改projectname以一些其他的名字?

我檢查了手冊頁Cargo 文檔 我也跑了:

  • cargo help
  • cargo --list
  • man cargo

在元數據文件(Cargo.toml、Cargo.lock、...)中,有“名稱”和“路徑”。 我想我可以手動更改它們,但我不知道這是否會破壞任何東西。

什么是最好的方法來做到這一點?

我認為您應該手動更改它。 沒那么難,真的。

我運行這個代碼:

$ 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得到了無用的文件,所以我建議無論如何刪除這些文件。

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

希望這可能會在將來對某人有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM