I want to take over the no longer maintained open source Rust package that is already deployed in crates.io.
While it is obviously in place and appropriate to require a different name for my fork in Cargo.toml, I would prefer not to require changes in the rest of the code, to make switching easier for potential users. When I simply renamed the entry in Cargo.toml, lots of code got broken everywhere. Exactly the old name is required.
It looks more logical to provide pluggable implementations of the same functionality the user can easily switch between, comparing performance and results of the own tests.
As a workaround, I am currently specifying the git URL in Cargo.toml:
old_name = { git = "https://github.com/new_repository", branch = "1.0.0" }
This works for me when testing my own deployment. But I probably should prefer crates.io for a public open-source project.
Is it possible to deploy a project on crates.io under a different name than the package name as referenced in the code, and how? I checked the documentation of cargo publish, but it does not seem to cover this case.
EDIT: If it is not possible to achieve this without refactoring, please give hints how to refactor the code that it would not require mass renaming every time the name of the package changes. Most of the references to the own package name seem to be in the tests.
A dependent crate can rename a dependency by specifying the package
(documentation). Here's how that'd look:
old_name = { package = "new_name", version = "..." }
This means that it will be accessible as old_name
in the code, but cargo will look for it as new_name
when resolving.
There is no way to publish as one name but have users use it with a different name besides this.
Most of the references to the [old] package name seem to be in the tests.
For renaming within the crate itself (for integration tests, examples, etc), you can avoid a complete refactor by using an alias in each scope it is used:
use ::new_name as old_name;