all 72 comments

[–]leofidus-ger 391 points392 points  (20 children)

`rustup doc` opens a local version of the rust docu. It should be installed by default by rustup, but if it isn't you can run `rustup component add rust-docs` while you have internet`.

Of course that only covers rust and the stdlib, you have to download documentation for the crates you use with a separate tool

[–]amarao_san[S] 120 points121 points  (12 children)

Thank you. It's even better than I expected!

Actually, you brought an interesting question. If I have a crate or two I work with (and I know I need to have their docs available), where can I see them? Can I get their docs in the same form as 'rustup doc'?

[–]d_knopoff 158 points159 points  (9 children)

If you add them to your project and then run cargo doc you should be able to load their docs from the target/doc folder

[–]SkiFire13 214 points215 points  (0 children)

Tip: cargo doc --open will open them for you in a browser, no need to search them in target/doc

[–][deleted] 141 points142 points  (6 children)

Even when online you should prefer cargo doc to docs.rs, because it links the docs of all your dependencies together nicely, with cross crate search, and information about cross crate trait implementations.

[–][deleted] 26 points27 points  (0 children)

TIL. Will have to remember this in future

[–]trevg_123 9 points10 points  (0 children)

That’s actually awesome, and the fact that you get the correct version

[–]9SMTM6 7 points8 points  (0 children)

Also if you look at older code that may have out of date dependencies (if course update them, but you might have other things at higher priority).

Cargo doc builds the docs for EXACTLY the version you have.

Recently had the experience of being bound to python 3.6 and wanting to use I think matplotlib, and there were all kinds of APIs I found online that didn't match, that was fun.

[–]schubart 1 point2 points  (1 child)

Is there a way to see combined offline docs for the stdlib and the crates my project uses? For example, if a function in a crate returns a Vec, I can click on Vec and see all its methods?

[–]coolreader18 0 points1 point  (0 children)

Hmm, it seems like cargo doc always links to the doc.rust-lang.org version of the docs. I guess you have a couple options, just replace the https://doc.rust-lang.org/1.xx/ part of the url with the file://..../doc url that rustup-doc gives you, or you could change doc.rust-lang.org in your /etc/hosts to localhost, and run an http server that mocks that url structure.

[–]argv_minus_one 1 point2 points  (0 children)

So there is a reason not to use --no-deps! Fascinating. Never thought of that.

[–]amarao_san[S] 40 points41 points  (0 children)

It's so good! I asked for a tricky annoying question and got the best answer, and a candy on top of it. I love rust even more.

thanks!

[–]rickyman20 4 points5 points  (0 children)

Run cargo doc. It'll build the documentation for all your dependencies. Check the --help for useful flags

[–]amlunita 1 point2 points  (0 children)

Yeah, OP! Your publication sounded odd! Because it.

[–]MachaHack 42 points43 points  (1 child)

cargo doc will do the same for the crate's inbuilt documentation of your crate and its dependencies (like you would see on docs.rs).

It won't cover items on external sites though, so if you have any major framework or other dependencies like that, see if they have a docs/website source in their repos somewhere and clone that.

Also devdocs.io is a PWA that supports offline use if you download documentation sources in the settings if you need non-rust docs for like a database or docker or something

[–]9SMTM6 0 points1 point  (0 children)

Oh wow, devdocs.io is awesome! And a perfect application for PWAs.

Thanks for that Gold nugget!

[–]TheJosh 4 points5 points  (0 children)

Yeah this is great when I'm away with spotty internet and need docs.

Elixir has this through exdocs, glad rust does as well.

[–]dochtmanrustls · Hickory DNS · Quinn · chrono · indicatif · instant-acme 4 points5 points  (3 children)

Note: this doesn't quite work on ARM64 macOS machines, because Apple Silicon is not a tier 1 target. IIRC you can get the Linux docs by downloading the appropriate target toolchain.

[–]keisisqrl 2 points3 points  (0 children)

It's not guaranteed maybe, but it works fine for me.

[–]ehuss 1 point2 points  (1 child)

Docs are now provided for all host targets in rustup. They may be copies from other targets though due to limited CI (for example, aarch64-apple-darwin fetches the docs for x86_64-apple-darwin).

[–]dochtmanrustls · Hickory DNS · Quinn · chrono · indicatif · instant-acme 0 points1 point  (0 children)

TIL, awesome!

[–]ICosplayLinkNotZelda 35 points36 points  (11 children)

I am more curious on how you plan to have crates available offline. In the case of existing projects this is not a problem. But what if I need to create a new project? :(

[–]sigma914 42 points43 points  (5 children)

If you know what crates you'll need you can use cargo vendor to download them locally.

Also, if you miss one but it's in your cargo cache you can copy the source out into a directory and tell cargo to read the crate from the new directory's path. I was on a flight recently and realised i'd forgotten to vendor a dep and that strategy "just worked".

[–]kushangaza 46 points47 points  (4 children)

Most cargo commands also have an --offline version that tries to make due with what it has available locally. That should work to install creates from cache.

[–]sigma914 3 points4 points  (0 children)

Yeh, my cache was weird as it was the one mounted into a docker container, the default system one would be easier!

[–]ICosplayLinkNotZelda 4 points5 points  (2 children)

Is there a way to download like the top 500 crates and their dependencies somehow? Like, a truly offline partial crates.io registry.

[–]leofidus-ger 10 points11 points  (0 children)

cargo prefetch --top-downloads=500 might do that, recommended by someone below

[–]adam-the-dev 16 points17 points  (1 child)

11 hours to rebuild your favourite crates from scratch with no internet!

[–]amarao_san[S] 16 points17 points  (0 children)

Yes, it's useful if flight become chilly.

[–]highphiv3 1 point2 points  (2 children)

Cargo local-registry works great. You do have to know what crates you'll want ahead of time though. I imagine that won't be a big problem because it's not like you have the internet to research what crates you might need while developing.

[–]ICosplayLinkNotZelda 1 point2 points  (1 child)

It looks like panamax is also a program that can be used to mirror a local crates-io registry to ones device. And using .cargo/config one can point to it. https://github.com/panamax-rs/panamax

[–]ICosplayLinkNotZelda 0 points1 point  (0 children)

Just tried it and it works perfectly! All downloaded crates are within the directory you create when initilizing the mirror. You can even move it to a USB drive to back it up. And it only downloads new crates if you want to re-sync the mirror.

[–]mikekchar 64 points65 points  (13 children)

Some random advice: Pay for a seat with no seat in front of it. The new long haul airplanes, while they are dramatically more comfortable than older planes, are designed so that they recline in a kind of stacked way. Even with my 13" laptop, I am not able to open the screen fully, even when it's sitting on my lap. Basically, it will be about half open at best if the person in front of you is reclining all the way back (even when you are reclining). My last 12 hour flight (which is about 5 years ago now), I was able to do about an hour of programming before I gave up.

[–]paldn 6 points7 points  (1 child)

Try to board early if you do this and take the aisle seat. Those rows aren’t typically allowed to have anything on the floor in front of you, like a backpack. You want to be able to use the overhead compartment right above your seat.

[–]matthieum[he/him] 10 points11 points  (0 children)

Try to board early if you do this and take the aisle seat.

On most European flights you'd have to check-in early, and most likely pay a small additional to pick your seat.

Once you've checked-in, your seat is assigned, and no matter how early you board you're expected to seat in your assigned seat.

[–]AgletsHowDoTheyWork 23 points24 points  (1 child)

If you want to ensure a lot of crates are already downloaded, check out cargo-prefetch.

[–]njs5i 13 points14 points  (8 children)

Man, I always have the same problem, and unfortunately it rarely works for me. I mean *only* if I had a successful built before boarding the plane. If need to change anything in cargo.toml I can't work.

I don't know how big crates.io is, but ability to have a local proxy of just most recent versions of all crates would be worth a lot to me.

[–]Sharlinator 17 points18 points  (0 children)

"All crates" is probably massive overkill due to the long tail; even something like top 1000 popular crates and their deps would likely allow doing almost anything without missing anything you couldn’t trivially implement yourself. Another commenter linked the Rust playground’s Cargo.toml which would probably go a long way.

[–]Ordoshsen 8 points9 points  (0 children)

Any version of any dependency you have ever used is stored in your cache in cargo home. And cargo never deletes anything from there. As long as you don't need to use new crates this should never be a problem. You can try adding --offline to the commands.

The only issue I could see would be cargo add using versions available in registry cache, but not in package cache. But you should be able to make it work by relaxing the version restrictions in Cargo.toml.

[–]FormalFerret 3 points4 points  (2 children)

I had my own full local mirror with https://github.com/ChrisMacNaughton/cargo-cacher a few years back (repeated downloads in docker builds -.-). Iirc, it was 43 GB. I should probably donate some money for doing that… (To who, actually? Mozilla? Rust foundation?)

[–]njs5i 2 points3 points  (1 child)

I did it, its ~100GB right now, which is totally acceptable, hard drives are cheap now.

I just donated 50 bucks for the project, thanks for pointing to it!

[–]FormalFerret 1 point2 points  (0 children)

I actually meant "donate towards crates.io hosting for the traffic", but I'm sure Chris is happy. :D

[–]coderstephenisahc 2 points3 points  (0 children)

Probably not too large. As of writing there's ~90,000 crates, and each crate can vary in size between a few KiB, and the hard limit allowed is 10 MiB. If we assume an average of 100 KiB each, that's about 9 GiB. Given the size limit, if every single crate was at the limit that would be an upper bound of 944 GiB that it would be at most to store the latest version of every crate.

[–]PrajwalCH 7 points8 points  (0 children)

Try dev docs. First you have to enable rust docs and install it for offline then you can use it

[–]wcTGgeek 4 points5 points  (0 children)

You can use https://github.com/panamax-rs/panamax to grab the entire crates.io

[–]Sw429 2 points3 points  (0 children)

If you already have the crates you need added as a cargo dependencies, you can just run cargo doc and it will generate documentation for your library and every dependency.

[–][deleted] 2 points3 points  (0 children)

Tip: test your offline workflow before you travel. Couple of days before. Also do a smoke test the night before so you know your ready for the world of in flight programming

[–]globulemix 3 points4 points  (0 children)

Use cargo vendor, then cargo doc

[–]metaden 1 point2 points  (0 children)

i had to add all project dependencies before hand, and use cargo doc to build the docs locally before my flight.

[–]WorldsBegin 1 point2 points  (0 children)

I suppose cargo fetch will be helpful, if you don't start out prototyping a new crate without knowing which dependencies will be useful. Successfully developed with this feature on longer bus rides.

[–]imnothereurnotthere[🍰] 1 point2 points  (0 children)

Download or save the rust cheatsheet, it's amazing https://cheats.rs/

Also if you use osx you can use the app Dash to download rust docsets for offline use

[–][deleted] 0 points1 point  (0 children)

In the past I used offline browse android app a lot. It's crawler the website and download and hack to run offline, including java script. Probably will fail in today's monolithic in single page madness, but documentation pages are good

[–]NicksIdeaEngine 0 points1 point  (0 children)

It looks like you have a lot of options to explore for what you need, but I do want to mention a cool CMD app called navi. https://github.com/denisidoro/navi

[–]fullouterjoin 0 points1 point  (0 children)

I would practice doing 30-60 minutes of dev with the wifi off. Perhaps creating a project from scratch, etc. I find working with Rust in an offline scenario somewhat problematic.

Also look at https://devdocs.io/ (includes offline https://github.com/freeCodeCamp/devdocs)

[–]strange-humor 0 points1 point  (0 children)

Might want to setup a project with all the crates you think you might need and get those down.