Last active
August 29, 2015 14:04
-
-
Save soli/300a8627a20ed9af8ade to your computer and use it in GitHub Desktop.
A tentative and very crude answer for http://www.reddit.com/r/rust/comments/2bvd33/is_there_a_tool_to_output_the_type_for_a_rust_name/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/</</g;s/>/>/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[*]} |
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
Use like this: