Type search for Rust docs

I've just had my first non-trivial contribution to Rust merged. It adds basic type search functionality (a la Hoogle) to rustdoc generated documentation.

The change is live on nightly builds, and you can already see it in action.


demo of searching for charext -> bool in the stdlib docs

The current feature set includes:

  • searching by type (you can use generics as well, as long as you use the exact name: vec, t ->)
  • the order of function arguments is not relevant (so you don't have to remember it)
  • self's type is took into account (e.g. Vec::len is vec -> usize)
  • reference types are treated as basic types (e.g. char, not &char)

If you are interested in the technical details, I suggest you check out the original issues, as well as the PR. While this is in no way comparable to a full fledged implementation like Hoogle's, the basic searching need is covered, and I hope that it will at least help other newbies like me explore the standard library, if nothing else.

There are plenty of enhancements to be made, so if you feel like contributing, here are a few ideas:

  • proper support for generics (char -> char should match t -> t)
  • smart ranking (char -> char should first match char -> char results, and then t -> t)
  • support for complex, wrapped types (e.g. Rc<Vec<T>>)
  • look for trait implementors (char -> bool should include charext -> bool results)
  • use compression for the search index (it was pretty large to begin with and it takes up even more space now, with the type information)

Last but not least, I'd like to give kudos to the Rust community. They were extremely helpful, both on IRC and on GitHub, and this helped make a daunting task (at first) seem doable!

Happy hacking!

Mihnea Dobrescu-Balaur

Building @Hootsuite Analytics. Interested in Open Source, programming languages and the Open Web. Big fan of basketball and photography. Tweet @mihneadb.

Bucharest, Romania

Subscribe to Mihnea DB

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!