# Support URI/Java-form crate names

**URL:** <https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379>\
**Category:** language design\
**Created:** [September 12, 2022, 8:09pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379 "2022-09-12T20:09:03Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![hydroper1](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hydroper1/32/12099_2.png) [@hydroper1](https://internals.rust-lang.org/u/hydroper1)\
**Post date:** [September 12, 2022, 8:09pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/1 "2022-09-12T20:09:03Z")

</div>

I'd like to hear what you think if we could have organization-scoped package names, using URI or Java form.

```rust
// URI-like
use "www.qux.org/foo"::*;
use "www.john.me/services/whatever"::*;

```

(In fact in NPM both `'@qux/foo'` and `'org.qux.foo'` work as package names.)

* * *

Note, this was suggested before, but proposing a different form of namespacing.

If the string literal is an issue, then I've another suggestion, in the form of Java package identifiers but using `::` as delimiter:

```rust
use org::qux::foo::*;

```

---

<div class="post-metadata">

**Author:** ![bascule](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bascule/32/3057_2.png) [@bascule](https://internals.rust-lang.org/u/bascule)\
**Post date:** [September 12, 2022, 8:22pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/2 "2022-09-12T20:22:02Z")

</div>

You might want to check out the most recent Namespacing RFC:

> **[GitHub - Manishearth/namespacing-rfc: RFC for Packages as Optional Namespaces](https://github.com/Manishearth/namespacing-rfc)**
>
> RFC for Packages as Optional Namespaces. Contribute to Manishearth/namespacing-rfc development by creating an account on GitHub.

There is a prototype which uses the URL-like `/` separator for namespaces here:

> <https://github.com/Manishearth/namespacing-rfc/issues/10>
>
> TL;DR go to https://cratespaces.integer32.com/ and follow the instructions to tr…y out crates-as-namespaces with \`/\` as the separator!
> 
> If you don't know what this is, check out \[the text of this draft RFC\](https://github.com/Manishearth/namespacing-rfc/blob/main/0000-packages-as-optional-namespaces.md).
> 
> \## What was built
> 
> Thanks to @stephanbuys, @JWorthe, and @tshepang of \[Caeg Industries\](https://github.com/caeg-industries) who built this prototype! 
> 
> It consists of:
> 
> \- \[A fork of crates.io\](https://github.com/caeg-industries/crates.io) that accepts \`/\` as a crate name character to allow the creation of sub-crates in the same namespace. Owners of the top-level crate have permissions to publish the sub-crates and automatically get permissions to any sub-crate.
> \- \[A fork of Cargo\](https://github.com/caeg-industries/cargo) that recognizes \`/\` as a valid crate name character and converts it to \`\_\` for compilation purposes
> \- Documentation and tests for this behavior
> 
> So you should be able to:
> 
> \- Publish a crate named \`foo\` and then publish subcrates \`foo/bar\` and \`foo/baz\`
> \- Depend on crates at the top of a namespace and in a namespace
> 
> Notably, no changes to rustc are needed for this to work!
> 
> I'm managing the running crates.io forked instance -- please ping me if it needs to be cleared out or if it goes down or something.
> 
> \## What wasn't built
> 
> We deliberately did not implement support for Cargo features to try and resolve \[the ambiguous syntax issue\](https://github.com/Manishearth/namespacing-rfc/issues/4); they won't work with this prototype 🤷‍♀️
> 
> The forked instance deliberately doesn't include the current crates.io database right now; we're \[ignoring migration paths\](https://github.com/Manishearth/namespacing-rfc/issues/5) for this experiment.
> 
> \## How to help
> 
> Please follow the instructions at https://cratespaces.integer32.com/ to try out this behavior and report if it does or does not work as you would expect, given your understanding of \[the RFC text\](https://github.com/Manishearth/namespacing-rfc/blob/main/0000-packages-as-optional-namespaces.md).
> 
> Especially \[open new issues on this repo\](https://github.com/Manishearth/namespacing-rfc/issues/new/choose) for any problems you encounter that we haven't considered yet! Please DO NOT open issues on crates.io's repo as we have not decided whether this is the functionality we want yet and it is definitely not supported for real!

---

<div class="post-metadata">

**Author:** ![hydroper1](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hydroper1/32/12099_2.png) [@hydroper1](https://internals.rust-lang.org/u/hydroper1)\
**Post date:** [September 12, 2022, 8:24pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/3 "2022-09-12T20:24:28Z")

</div>

I see, thanks. It seems they still use underscore in user code, though.

---

<div class="post-metadata">

**Author:** ![Nemo157](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nemo157/32/11585_2.png) [@Nemo157](https://internals.rust-lang.org/u/Nemo157)\
**Post date:** [September 12, 2022, 8:26pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/4 "2022-09-12T20:26:24Z")

</div>

What's the purpose of having a url-like crate name? Does this provide any advantage over `org_qux_foo_lib` or hosting your own registry to allow `foo-lib = { registry = "qux.org" }`?

---

<div class="post-metadata">

**Author:** ![hydroper1](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hydroper1/32/12099_2.png) [@hydroper1](https://internals.rust-lang.org/u/hydroper1)\
**Post date:** [September 12, 2022, 8:29pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/5 "2022-09-12T20:29:11Z")

</div>

The URI is more self-explanatory that what precedes `.org` is an organization. It indicates an `org` domain (think, it could also be `.me`!) and the dot character even keeps it well separated from the crate name. But it'd be pratically the same thing as Java's case...

With the URI idea there are the domain separator and one or more of the slash separator. With the Java idea there are only one or more of the dot separator.

I also just thought of adding a `www.` prefix for more legibility. (This is up to the user, optional convention.)

Also, this URI idea has been due to XML namespaces from which I took inspiration. The URI doesn't correspond to a HTTP transaction.

I updated the OP with few more examples of the URL idea.

---

<div class="post-metadata">

**Author:** ![anon32976453](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anon32976453](https://internals.rust-lang.org/u/anon32976453)\
**Post date:** [September 13, 2022, 12:29pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/6 "2022-09-13T12:29:10Z")

</div>

The Java scheme can be quite good but it is certainly not perfect. The downside to this global URL (and yes, the proposed scheme is **not a URI** ) is that it can easily break when projects change ownership. Consider a project such as QT which has changed hands many times since its creation. having the original company name as part of all the identifiers would be a major issue for the latest owner.

That's perhaps the subtle distinction between URL and URI - A URL describes a location (the current company that owns the code, a transient property) whereas a URI describes an **immutable** identification. For example we have such schemes to identify books.

The above mentioned RFC addresses the underscores issue only within the project which is correct. The additional information (company name) you want to add to crate names would be better done as associated metadata.

IMO, a company should have a private registry for its internal code as suggested above. Alternatively, for publishing OSS [crates.io](http://crates.io) ought to be slightly extended IMO to allow cargo to optionally reference projects by users/accounts. This shouldn't leak into the code though as the association belongs in the cargo.toml manifests only. Something like:

```
[dependencies]
    SomeOpenSourceProject = { version = "1.0", account = "MyCompany" } 
    SomePrivateProject = { version = "1.0", registry = "MyCompany.com" }

```

I reckon this would help grow the ecosystem and encourage the big enterprises to publish Rust open source libraries & projects. The current policies of [crates.io](http://crates.io) are way too dogmatic for my taste at the moment - e.g. the current restriction that published crates must not depend on external registries could be relaxed within such accounts.

---

<div class="post-metadata">

**Author:** ![hydroper1](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hydroper1/32/12099_2.png) [@hydroper1](https://internals.rust-lang.org/u/hydroper1)\
**Post date:** [September 13, 2022, 12:57pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/7 "2022-09-13T12:57:48Z")

</div>

Makes sense, but NPM uses the kind of namespacing proposed anyway... and it'd be an advantage to know who owns the crate in the user code.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [September 13, 2022, 1:00pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/8 "2022-09-13T13:00:07Z")

</div>

If these URIs are supposed to be the source the crate is fetched from (like Golang or Deno do), then it's a security risk when the domain expires (you can't expect someone to hold on to a domain forever, especially if it's a non-commercial open-source project). The new domain owner could inject arbitrary code into existing projects. [crates.io](http://crates.io) offers longevity and immutability of the sources.

And if these are supposed to be names of crates on [crates.io](http://crates.io), then it's just confusing to use a different URLs for them. Also [crates.io](http://crates.io) would have to verify domain ownership, because otherwise anyone could squat any domain and have even worse false legitimacy.

Adding dependencies with `use` would make it harder to analyze project's dependencies. `Cargo.toml` has an advantage of being an easy-to-parse central place.

---

<div class="post-metadata">

**Author:** ![hydroper1](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hydroper1/32/12099_2.png) [@hydroper1](https://internals.rust-lang.org/u/hydroper1)\
**Post date:** [September 13, 2022, 1:05pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/9 "2022-09-13T13:05:15Z")

</div>

I meant URIs as identification strings only (not HTTP transaction). You're right, maybe Cargo would have to verify the URI domain parts.

About the dependency, it'd still have to be added to `Cargo.toml`, that is, something like:

```rust
[dependencies]
"www.feathersui.com/aeon" = "1.0.0"

```

---

<div class="post-metadata">

**Author:** ![jjpe](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jjpe/32/9779_2.png) [@jjpe](https://internals.rust-lang.org/u/jjpe)\
**Post date:** [September 13, 2022, 5:20pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/10 "2022-09-13T17:20:10Z")

</div>

In my opinion, one of the things Rust does better than Java w.r.t. ergonomics is the omission of URLs in e.g. import statements. I am actively happy with the status quo.

The main reason is that import URLs are unreasonably unergonomic to type, a akin to a git dependency. The difference between the 2 is that use statements are used much more than dependency entries in Cargo.toml. In effect, I consider URLs in import statements a usability hazard. It might not.bother those using IDEs that automatically do imports as much, but that is definitely not close to 100% of the community.

In addition, the rest of the URL other than the crate name is **just noise**. That is to say, it conveys no information that is useful at the level of the program to either me as the author /reader of the code, or to rustc. For example, at the level of code I _don't care_ where it comes from, just that it is unambiguously resolved when I import it. And that is one thing the status quo is exceedingly good at.

And if it did convey useful information, conceptually speaking I think its place would be where all metadata for a crate lives: in its Cargo.toml.

The third reason is the use of strings. Stringly typed language constructs always make me uneasy, it feels way too unsafe. It's the same issue as in any random program in a statically types language, except magnified because it's part of the core language. Note that it is also a usability hazard in this way: strings don't get e.g. syntax coloring or internal error checking other than basic "does this match a reasonable regex for a URL?"

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [September 13, 2022, 5:55pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/11 "2022-09-13T17:55:36Z")

</div>

> [@anon32976453](#):
>
> That's perhaps the subtle distinction between URL and URI - A URL describes a location (the current company that owns the code, a transient property) whereas a URI describes an **immutable** identification. For example we have such schemes to identify books.

Almost, but not quite. A URL (uniform resource locator) is indeed a location. A URN (uniform resource name) is an immutable identification. A URI (uniform resource identifier) is either a URL or a URN.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [September 13, 2022, 11:46pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/12 "2022-09-13T23:46:30Z")

</div>

I go by [the WHATWG spec](https://url.spec.whatwg.org/):

> Standardize on the term URL. URI and IRI are just confusing.

---

<div class="post-metadata">

**Author:** ![piegames](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/piegames/32/9140_2.png) [@piegames](https://internals.rust-lang.org/u/piegames)\
**Post date:** [September 15, 2022, 8:45pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/13 "2022-09-15T20:45:54Z")

</div>

> [@bjorn3](#):
>
> URI (uniform resource identifier) is either a URL or a URN.

Also wrong. URNs and URLs are URIs, but there are URIs that are neither. (Apart from that, I agree with @kornel and the WHATWG spec: the battle for distinguishing these terms is long lost, too many people already use them interchangably)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [December 14, 2022, 8:46pm UTC](https://internals.rust-lang.org/t/support-uri-java-form-crate-names/17379/14 "2022-12-14T20:46:32Z")

</div>

Closed on December 14, 2022, 8:46pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
