crates.io currently places all registered packages in a single flat namespace. This simplifies some aspects of package discovery, but adds friction for users who prefer to name packages after their purpose rather than use an opaque codename. Additionally, due to the large number of registered packages, it is often difficult to find a name that is short enough to be ergonomic when referenced as a symbol.
The typical solution to this problem is package namespaces, and the topic has been covered before (links copied from HN discussion):
These proposals have focused on one type of namespace, the "organizational namespace", which would allow "@example/foobar"
to be a crate managed by Example Inc. Then they struggle to make progress on difficult non-technical aspects such as allocation of names.
I propose adding a more limited form of namespacing, for user accounts only:Jane Doe, who created her account by signing in with the GitHub account jdoe
, will be able to publish crates with names prefixed by "~jdoe/"
. This is in addition to the existing non-namespaced crates policy.
The tilde prevents conflicts with existing crate names, is separate from any future proposals for organization namespaces, and has that charming mid-90s Geocities aesthetic.
This syntax will also be recognized by Cargo, which will drop the prefix when assigning a package to a crate name. In other words, these two [dependencies]
sections would be equivalent:
[dependencies]
foo = { version = "0.1", package = "~jdoe/foo" }
[dependencies]
"~jdoe/foo" = "0.1"
This makes the use of user-namespaced crates more ergonomic -- the dependent crate does not need to manually rename.