Rust local docs and Xfce

One of the best things about programming in Rust is the fantastic documentation. And one the best things about Rust documentation is that it's all available locally, even when you're not online.

You can read "the book" with

❯ rustup doc --book

"The Rustonomicon" with

❯ rustup doc --nomicon

or look something up in the manual with

❯ rustup doc std::collections::HashMap

All of these should open local HTML documentation in your default web browser. My machine was opening them in Chromium, even though that wasn't my default.

❯ xdg-settings get default-web-browser
firefox.desktop

It looks like rustup doc ought to be calling xdg-open, but that does open in my default browser

❯ xdg-open http://www.freedesktop.org/

So what's going on? Running this

❯ rustup doc std::iter

opens this file

file:///home/tim/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/share/doc/rust/html/std/iter/index.html

Is it because of the "file" URL?

❯ xdg-open file:///home/tim/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/share/doc/rust/html/std/iter/index.html

Yes, this opens in Chromium, not Firefox!

Turns out there's more to xdg-open than just the default web browser. Things are also configurable by MIME type. I'm using Xfce, so looking at Applications -> Settings -> Default Applications, we can search for chromium in the "Others" tab.

./default-applications.png

Sure enough, there are several things set to Chromium! I'm not sure how that happened, but setting the text/html one to Firefox makes xdg-open (and hence rustup doc) use Firefox instead.

./text-html.png

By the way, in addition to all the great docs that ship with Rust, you can also generate and view your own docs locally too. If I'm in the project directory for the epochs crate, then

❯ cargo doc --open

will generate a page similar to this one and open it in my default browser (well, now it will 🙂).