Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to rename a Cargo project?

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?

like image 773
David Varela Avatar asked Jul 04 '17 18:07

David Varela


People also ask

What is project cargo and how does it work?

Project cargo is a type of cargo that is oversized, typically high value and out of gauge cargo (OOG), requiring special equipment such as cranes, forklifts, trucks or tools to move. This type of cargo is transported by utilizing specialized vessels, train wagons, trucks or aircrafts.

What are the challenges of moving project cargo?

Moving project cargo also requires proper appreciation for safety, an eye for detail, and a systematic plan that considers various logistical challenges such as road, weather, availability and transportation conditions. Project cargo is found in a wide variety of applications.

How is cargo transported in the transportation industry?

This type of cargo is transported by utilizing specialized vessels, train wagons, trucks or aircrafts.


2 Answers

I think that you should change it manually. Not so difficult, really.

I run this code:

$ 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

From all these files, the whole target may be just deleted. The .lock file can also be deleted. And the Cargo.toml... well you can just edit it.

I tried changing only the Cargo.toml and all just works. However you end up with useless files in target so I recommend deleting those anyway.

like image 113
rodrigo Avatar answered Sep 20 '22 19:09

rodrigo


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

like image 39
Julius_Gu Avatar answered Sep 21 '22 19:09

Julius_Gu