Skip to content

Instantly share code, notes, and snippets.

@dbp
Created October 9, 2012 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbp/3861243 to your computer and use it in GitHub Desktop.
Save dbp/3861243 to your computer and use it in GitHub Desktop.
announce rustle
I'm announcing an initial version of an API search tool for Rust. It is inspired by the api search tool for haskell
called Hoogle (http://www.haskell.org/hoogle). It is very new (I started working on it a week ago), so it has a long
way to go, but for a taste of the kind of things it can currently do:
rustle> str -> uint
core::str::capacity - fn capacity(s: & const ~str) -> uint - Returns the number of single-byte characters the
string can hold without reallocating
core::str::char_len - fn char_len(s: & str) -> uint - Returns the number of characters that a string holds
core::str::len - fn len(s: & str) -> uint - Returns the string length/size in bytes not counting the null terminator
rustle> Either<A,B> -> A
core::either::unwrap_left - fn unwrap_left<T, U>(eith: Either<T, U>) -> T - Retrieves the value in the left branch.
Fails if the either is Right.
rustle> Either<uint,uint> -> uint
core::either::unwrap_left - fn unwrap_left<T, U>(eith: Either<T, U>) -> T - Retrieves the value in the left
branch. Fails if the either is Right.
core::either::unwrap_right - fn unwrap_right<T, U>(eith: Either<T, U>) -> U - Retrieves the value in the
right branch. Fails if the either is Left.
rustle> Option<D>,Option<D> -> Option<D>
core::option::or - fn or<T>(opta: Option<T>, optb: Option<T>) -> Option<T> - Returns the leftmost some()
value, or none if both are none.
rustle> each
core::str::each - fn each(s: & str, it: fn&(u8) -> bool) - Iterate over the bytes in a string
core::vec::each - fn each<T>(v: &r/[T], f: fn&(&r/T) -> bool) - Iterates over a vector, with option to break
core::vec::each_mut - fn each_mut<T>(v: & [mut T], f: fn&(elem: & mut T) -> bool) - Like
core::vec::each_permutation - fn each_permutation<T: Copy>(v: & [T], put: fn&(ts: & [T]) -> bool) -
Iterate over all permutations of vector
rustle> Option<uint> -> uint
core::option::get - fn get() -> T - a method of Option<T>: Gets the value out of an option
core::option::get - fn get<T: Copy>(opt: & Option<T>) -> T - Gets the value out of an option
...
It will search for functions by types (with tolerance to renamed type variables - i.e., Option<D>
matches Option<T>). It will also try to look for more general functions (i.e., Option<uint> -> uint
matches Option<T> -> T), and rearrange the order of arguments. There is limited support for methods -
we include ones declared on types, but not ones that come through traits.
There are also massive simplifications (and many limitations) - all pointer types are ignored, all
single letter uppercase types are treated as polymorphic (so trait constraints are ignored), and a
couple other problems (chiefly that function arguments are not understood). You can search for
functions by names, but only prefixes (this limit will go away eventually). On the other hand,
it already does some neat things!
To try it out, contribute, improve, file bugs, etc, go to http://github.com/dbp/rustle . The readme
should explain how to get started with it. It is currently a command line program, but I'm hoping
in the near future to write a simple web frontend for in. It is all written in rust, except the
html scraper (which is not needed to run it).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment