roogle
roogle copied to clipboard
Rust API search engine
- Roogle This is a modification of Hoogle to allow searching Rust type signatures.
See https://github.com/ajtulloch/rust/tree/roogle for the RustDoc modifications necessary.
** Approach RustDoc generates JSON type signatures for method/functions invocations, of the form in Haskell #+begin_src haskell data Type = TApp Type [Type] -- a list of types, first one being the constructor | TLit String -- bound variables, Maybe, ":", "(,)", "(,,)" (tuple) | TVar String -- unbound variables, "a" | TFun [Type] #+end_src
or in Rust, #+begin_src rust pub enum HType { App(Box<HType>, Vec<Box<HType>>), Lit(String), Var(String), Fun(Vec<Box<HType>>) } #+end_src
For example, #+begin_src rust fn lookup<T>(x: Vec<T>, y: int) -> Option<T> #+end_src
has the Hoogle type #+begin_src haskell TFun [TApp (TLit "(,)") [TApp (TLit "Vec") [TVar "T"], (TLit "int")], TApp (TLit "Option") [TVar "T"]] #+end_src
Note that this does not capture the full generality of Rust's type system (e.g. we ignore mutability, references, lifetime annotations). Thus when searching we don't distinguish between cases like: #+begin_src rust fn function_1(x: &int, y: &int) -> int fn function_2(x: int, y: int) -> &int #+end_src
These are generated by RustDoc in the course of the usual HTML generation approach, and Roogle parses these JSON files to construct it's type database.
Once Roogle has the type signatures, we can use the existing sophisticated type-search infrastructure to search for types (see http://community.haskell.org/~ndm/hoogle/ and links therein for more detail). ** Currently Implemented
- Free Function
- Method Implementations ** Usage First, generate the documentation =hoogle.json= files from RustDoc. (in =$RUSTDIR$=) #+begin_src sh make docs #+end_src
Next, parse the JSON files and generate the Roogle databases. (in =$HOOGLE_DIR$=) #+begin_src sh cabal build dist/build/hoogle/hoogle rustdoc $(find $RUSTDIR/doc -iname 'hoogle.json') #+end_src
Finally, send some queries to Roogle, #+begin_src ∴ dist/build/hoogle/hoogle search "Path -> Path" | head -n8 "Loading database: ./rust.hoo" Warning: Unknown type Path clone :: Path -> Path dir_path :: Path -> Path make_absolute :: Path -> IoResult Path readlink :: Path -> IoResult Path realpath :: Path -> IoResult Path make_non_verbatim :: Path -> Option Path #+end_src
#+begin_src tulloch at tulloch-mbp in ~/src/hoogle (roogle) ∴ dist/build/hoogle/hoogle search "(AtomicBool) -> bool" | head -n5 "Loading database: ./rust.hoo" Warning: Unknown type AtomicBool load :: AtomicBool -> Ordering -> bool compare_and_swap :: AtomicBool -> (,) bool bool Ordering -> bool fetch_and :: AtomicBool -> (bool, Ordering) -> bool #+end_src
You can also use the web interface, by calling
#+begin_src dist/build/hoogle/hoogle server --port 8080 #+end_src and navigating to http://localhost:8080. For example, #+ATTR_HTML: :width 400px [[http://i.imgur.com/mdiCh9R.png]]