Transition to namespaces #12307
tliron
started this conversation in
Feature Requests
Replies: 1 comment 1 reply
-
|
This is already in the works, but is a bunch of work. Accepted RFC: rust-lang/rfcs#3243
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
crates.io began, like PyPi and other library repositories, with a flat namespace.
This means that crate names can ever only be used once, and it has some painful consequences for both publishers and users.
Many "good" names are already taken. Moreover, it creates an anxiety about naming, which leads to people "parking" good names for which they don't have a project yet. Or just modifying their names to be "less good", to avoid conflicts with existing names, by adding silly and confusing prefixes and suffixes or other mangling. That's where it gets painful for users. Compare
serde_yamlwithserde_yml. Or many crates that add-rs. I've even seen crates that change from underscore to dash delimiters, or vice versa, in order to differentiate further! This is super confusing to everyone.To me, the obvious solution is to prefix crate names with a namespace, which can be the name of the developer, organization, project, etc. So there could be
acme/serde_yamlandradical/serde_yaml. Woosh, the anxiety about naming is gone and everyone can choose whatever name works best for them.Of course, the worry is about what to do with the current state of things. I would suggest the following transition plan:
First, create a
default(orlegacy?) namespace, to which all current crates will be moved. When referring to crates without a namespace (inCargo.toml,cargo add, etc.) this default namespace will be automatically added. So everything would continue to work as is with current crates.However, we would lock the
defaultnamespace from any new crates. Newly published crates would have to be in new, non-default namespaces.Honestly, the solution can end with this.
defaultwould remain frozen in time and that's that. A memory of cargo.io's past. :)But we can do some more things:
We could allow aliasing for these "legacy" names, to allow them to transition to a new namespace. For example, I have an
awesomecrate, which is reallydefault/awesome, I could alias it to a newradical/awesomenamespace. The alias means that aCargo.tomlcan useradical/awesome,default/awesome, or justawesome, and it would point to the same exact crate with all the same versions. We can decide that one of these aliases is the "canonical" name (likelyradical/awesome), and that's what would be used inCargo.lockand the like.We could furthermore decide that eventually the
defaultnamespace would be deprecated, perhaps coupled with other breaking changes to cargo. That means that well before the sunset date we would send emails to crate owners that they need to transition their crate to a namespace (aliased?) in order to keep it published. At the sunset date thedefaultnamespace would no longer be available.Obviously this last step would be more controversial, as it would break some very old projects. We can come up with ways to make this less bad. For one, if this is tied to a specific edition of cargo, then we could say that the
defaultnamespace would remain accessible only to these older editions of cargo. Newer editions would error out, but older projects based on the older edition would continue building and working as is.One could also argue that it's not the end of the world if very old projects stop building. If many years have passed without these crates being maintained, then maybe they should be sunset? Anyway, we have options here.
A second issue we would need to solve is what to do with module naming in Rust. If my
Cargo.tomlhas bothradical/awesomeandcompetitor/awesomeas dependencies, how would this affect module name paths? They can't both beawesome::*, right? Here there can be some sensible heuristics to keep things coherent and ergonomic.First, if there is no naming conflict in the dependencies then there's no reason to complicate things. If we only have
radical/awesomethanawesome::*could be mapped to it.Second, if there is a naming conflict then cargo can force you to add
packageto at least one of them, e.g.:I hope this all makes sense and I would be happy to hear about alternative solutions as well as arguments to keep things as is.
Beta Was this translation helpful? Give feedback.
All reactions