Skip to content

Instantly share code, notes, and snippets.

@soli
Last active Aug 29, 2015
Embed
What would you like to do?
#!/bin/bash
if [[ $# != 1 ]] ; then
echo "Usage: $0 <type/struct/trait/fn>"
exit 1
fi
if [[ $1 =~ '::' ]] ; then
query=$1
else
query=$(curl -L -s http://doc.rust-lang.org/std/prelude | sed -ne 's/^.*title=.\([^'\'']*\).>'$1'<.*$/\1/p')
fi
query=${query//::/\/}
path=$(dirname $query)
leaf=$(basename $query)
function do_query {
for q in $@ ; do
curl -s -f http://doc.rust-lang.org/${q}.html | sed -n '1h;1!H;${g;s/^.*\n<pre class[^>]*>\(.*\)<\/pre><.*$/\1\n/;s/<[^>]*>//g;s/&lt;/</g;s/&gt;/>/g;p}'
if [[ ${PIPESTATUS[0]} -eq 0 ]] ; then
break
fi
done
}
case $(basename $query) in
[A-Z]*) query=($path/{type,struct,trait}.$leaf) ;;
[a-z]*) query=$path/fn.$leaf ;;
*) echo "sorry couldn't parse $1" ; exit 1;;
esac
do_query ${query[*]}
@soli
Copy link
Author

soli commented Jul 28, 2014

Use like this:

> rustdef std::result::Result
pub enum Result<T, E> {
    Ok(T),
    Err(E),
}
> rustdef std::comm::channel
pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>)

@soli
Copy link
Author

soli commented Jul 28, 2014

or even

> rustdef Result
pub enum Result<T, E> {
    Ok(T),
    Err(E),
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment