All hands: Crate grouping & Namespacing discussion

Crate grouping

  • Some concept of a “package” (need better name) that is multiple crates versioned together .
  • You can use one or more crate from the package, you need not use the toplevel one
  • Useful for splits like regex/regex-syntax, serde/serde-foo/serde-bar, servo’s dependencies
  • crate splits are useful for
  • compile times
  • better expressing cargo feature splits (can’t do this well with modules)
  • potentially can allow weaker coherence between crates. As long as they are versioned together this is fine

Crate namespacing


This is not an attempt to solve the squatting problem or a way to force namespaces.

Use cases:
  • Declaring crate affiliation in a stronger way:
  • rust-lang/rand: Official crates can be marked official
  • dalek/curve25519: folks name things curve25519-dalek, etc, but anyone can publish a crate named foo-dalek
  • Grouping together related crates e.g. regex & regex-syntax (becomes regex/syntax)


Choices for how the namespace works:

  • It’s a crate you already own (good for the regex or serde use case where you have a core crate  and a bunch of little thingies)
  • It’s a namespace you register that cannot conflict with a crate name(?)


There are different ways to handle importing:

  • Import as “foo/bar” in Cargo.toml. For handling the rustc side, we have options:
  • Aliasing (Cargo): We can force users to alias to an identifier in Cargo.toml (unwieldy)
  • Aliasing (Rust): We can force users to extern crate "foo/bar" as bar (unweildy and we want to get rid of extern crate)
  • Autorewriting: foo/bar is usable as foo_bar in the rust code (kinda weird, we don’t like the dash to underscore thing already)
  • Use :: : foo/bar can be imported as foo::bar in Rust code. It’s a bit weird, but not too bad
  • New sigil: We can just have / or @ for this (npm does this kinda with @)
  • Import as “bar” in Cargo.toml
  • This means that the foo namespace is only cosmetic (on the crates site) and doesn’t appear in the code. This does not let you avoid clashes, which is not the main goal here.
  • We can make it still possible to use foo/bar in Cargo.toml but we don’t have to (?)


The “import as ‘bar’” seems nicer, however it isn’t as good as handling crates like regex/syntax which are now called just “syntax” (and regex/regex-syntax looks kinda weird). Not having to deal with the aliasing problem is nice.