Workspace-centric `cargo add/remove`?

Gradually warming up to the concept of a workspace.

cargo new --lib inner_crate has got to be my new favourite thing to type.

Alas, there doesn't appear to be a simple way to add/remove an inner workspace member from the list of dependencies. Unless I'm missing something obvious? To clarify: is there a

  • cargo new --lib inner [--workspace/--dep]? - to
    • (a) create an inner folder
    • (b) add it in workspace.members of Cargo.toml
    • (c) add it as inner = { path = "./inner" } into workspace.dependencies
  • cargo remove inner [--workspace/--dep]? - to
    • (a) delete the same folder from the drive
    • (b) remove it from workspace.members and .dependencies

Or anything like it built-in and shipped with cargo?


Side question: it doesn't seem possible to have the name of the inner in the dependencies of the workspace itself be different from the path and/or (?) its own package.name - any idea why?

There isn't anything like that. new and remove aren't opposite of each other, that's cargo add and cargo remove. Cargo doesn't have anything to undo new, and probably won't, because deleting code is much more risky operation than generating some boilerplate code.

1 Like