Using Cargo to learn Rust libraries offline

Cargo is super awesome for Rust projects. I'm not going to give all the details about what you can do with it, but what's important to know is that it handles your dependencies for you much like maven or something like that.

Which means you need an Internet connection.

And if you're offline for 7 days on a giant boat and planning on spending some time learning Rust, this might be a problem.1

So, to work around this issue, here's a silly hack:

  1. Create a new dummy crate project (or multiple). cargo new depdummy; cd depdummy
  2. Add every dependency you think you might want to use to your Cargo.toml. Refer to the Cargo guide if you've never done this.2
  3. Either cargo build or cargo doc -- the latter is usually shorter to invoke.

Now, any time you want to make a new crate that depends on any of those dependencies you bookmarked, use the dependency versions referenced in the dummy crate, and copy the Cargo.lock file from the dummy crate into your new crate. This will ensure that Cargo already knows about the downloaded versions from the dummy, thus it will not update the index. All functionality of Cargo will be available to you offline, particularly doc.

  1. Every build system with a dependency manager suffers from this problem. Doing this is easier with some than others. It'd be nice if they all had a common way of building a local index; it's sort of possible to do this with Maven.

  2. If you run into versioning hell, this would be a good case to split your dep dummy crate into multiple.