Current Issues
The lack of namespaces for crates currently leads to several problems:
- Crate names being "squatted" or reserved unnecessarily.
- Popular crates being maintained by non-official parties, causing potential confusion.
Challenges with Introducing Namespaces
Introducing namespaces also brings its own set of challenges:
- Users may dislike having to include the owner's name in configuration files.
- Namespaces might not always indicate official ownership.
A New Proposal: Allowing Crates with the Same Name to Coexist
Here's an alternative idea: allow multiple crates with the same name to coexist.
Implementation
Each crate would be assigned a unique ID. The ID could increment sequentially for each new crate with the same name. The first crate published under a specific name would always have an ID of 0
for backward compatibility.
- When the crate name is unique on
crates.io
, the behavior remains the same as the current setup. If the ID is omitted, it defaults to0
.
foo = "1.0.0"
- When multiple crates share the same name,
cargo add
would fail without specifying the ID. In this case, users would need to provide the crate's ID explicitly, like this:
foo = { version = "1.0.0", id = "1" }
- In extreme scenarios, where users need to use multiple crates with the same name simultaneously, this isn't an issue. Cargo already supports aliases for crates in
Cargo.toml
.
Example with Aliases
foo1 = { package = "foo", version = "1.0.0", id = "0" }
foo2 = { package = "foo", version = "1.0.0", id = "1" }
Apologies for the previous absurd and immature suggestion. I now propose an alternative approach that appears more intuitive (though equally impractical to implement) - a solution I believe most people would naturally consider:
foo = { version = "1.0.0", namespace = "bar" }
This approach suggests:
- Non-unique crate names on crates.io, while enforcing unique namespaces
- Implementing a namespace verification system on crates.io to indicate official ownership
- Potential future integration with IDE tools like VSCode to display verification badges in TOML plugins
Introducing namespaces at the Cargo.toml configuration level seems less intrusive than implementing them in code. While namespace squatting remains possible, this system would:
- Eliminate the need for developers to invent unique crate names
- Provide clearer ownership indicators
- Maintain backward compatibility
The trade-off between namespace contention and naming freedom might be more acceptable than the current naming collision challenges.