Where is the index (and code) for crates on crates.io stored?

Recently I came upon the crates.io-index repo on github, and I wonder why is this necessary? Does cargo pull the crate index from github every time I run cargo update?

And if it is, why github? If I understood correctly, every time a crate is published, a tarball is pushed to crates.io, which means that all the code is stored on crates.io, rather than, e.g. linking to github.

Hence, why have the index stored on github? Or is it for some other purpose, like having redundancy?

You can find many information about crates.io on their doc page: https://doc.rust-lang.org/cargo/

After some more digging I found out that cargo actually pulls the crates index from github and download crate content from crates.io. I guess it’s just a design choice to minimize server load or something. Nevermind, problem solved.

@hellow although I didn’t found any reference in the cargo book about this, thanks for the pointer anyway.

There’s some reasoning on why the index is stored in Git here:

The index is stored in a git repository so that Cargo can efficiently fetch incremental updates to the index.

Basically, Git is pretty good at incrementally updating files, so Cargo just piggybacks on this instead of having to implement something similar from scratch.

2 Likes

I see…That makes total sense, thanks!