Is there any way to rename a Cargo project?

Viewed 13080

I created a project using: cargo new projectname --bin. How do I change projectname to some other name?

I checked the man page and the Cargo documentation. I also ran:

  • cargo help
  • cargo --list
  • man cargo

In the metadata files (Cargo.toml, Cargo.lock, ...), there is "name" and "path". I suppose I could change them manually, but I don't know if that would break anything.

What would be the best way to do this?

2 Answers

Under Linux this is fairly strait forward:

  • go to the directory where your project is located e.g. if your project was called hello_world in a folder named rust then go to the rust folder pi@raspberrypi:~/workspace/rust/hello_world $ cd ..
  • from there you can rename the project by
    1. mv [current name of the project] [name you want] to move. E.g. if I wanted to rename it from hello_world to hello_rust I would type mv hello_world/ hello_rust/ to rename the folder.
    2. now you only have to change the name in your Cargo.toml file:
      • pi@raspberrypi:~/workspace/rust $ cd hello_rust/
      • pi@raspberrypi:~/workspace/rust/hello_rust $ geany Cargo.toml
      • (I am using geany but you can use whatever text editor you like)
      • in Cargo.toml in the second line change
      • name = "hello_world" to name = "hello_rust"

Hope that this might help someone in the future

Related