I feel like namespaces need to come, as soon as possible. it is essential for the rust ecosystem to stay healthy as it grows faster and faster. and IMO it is necessary for a central registry with contribution from individuals.
for instance, docker images from registries are namespaced, npm packages are namespaced (scoped), vscode extensions are namespaces on the marketplace. and notably, github repositores are namespaced, can you imagine your github repositories must have unique names across entire github?
also, some systems mitigate the name collision issue using convensions, such as go and java, I would consider them practically namespaced. however, the situation for languages like go and java is a bit different, they import packages by (hierachical) paths, e.g. import com.example.helloworld.cli.Main;
in java, which typically correspond to (arbitrarily deep) filesystem paths; as opposed to import by (namespace qualified) names, e.g. require('@example-com/helloworld-cli')
in js, which usually use flat or very shallow filesystem storage.
there's also some discussion about package name squatting recently.
the problem with cargo packages is, how to migrate to the namespaced system in a backward compatible way, and how should we import a namespaced package in code?
for the first problem, maybe we can use docker.io
for reference, e.g. if you do docker pull ubuntu:latest
, it resolves to a "official" library
namespace, namely, docker.io/library/ubuntu:latest
, and the web url for the image uses an underscore as the namespace, i.e. hub.docker.com/_/ubuntu
.
similarly we can reserve a "global" (or "default', or "_", to be bikeshedded) namespace, where all old packages should go, but new versoins are not allowed to publish there, the maintainers must setup a redirect target, and newer version of the same package must be published under their registered namespace. when cargo updates a legacy package, it can use the redirect to pull the new version, and prints a warning message to the user to inform the package renaming.
for the second problem, I have absolutely no idea. I'm not into the compiler at all, so I can just make wild hypothesis.
currently, we can only import a flat crate, i.e.
extern crate foo;
I'd imagine we have to do something like:
// warning:
// these are my imaginary syntax, they are NOT real rust
extern crate foo::{bar, baz};
extern namespace foo {
crate bar;
crate baz;
}
extern mod foo::{bar, baz}
extern crate foo {
mod bar;
mod baz;
}
// other posibilities...
again, I don't know what is feasible or what is preferred, I'm just imagining.