Skip to content

Instantly share code, notes, and snippets.

@kosh04
Created Feb 6, 2018
Embed
What would you like to do?
Rust playground command-line tool (simple)
#!/bin/sh
set -eu
usage="usage: $0 [execute|compile] FILENAME"
url=https://play.rust-lang.org/${1?${usage}}
code=$(cat ${2?${usage}})
send() {
curl -s -X POST -H "Content-Type: application/json" -d @- ${1}
}
case ${1} in
execute)
jo channel=stable mode=debug crateType=bin tests=false code="${code}" | \
send ${url} | \
jq -r "(.stderr, .stdout, .success)"
;;
compile)
jo channel=stable mode=debug crateType=bin tests=false code="${code}" \
target=mir assemblyFlavor=intel demangleAssembly=demangle hideAssemblerDirectives=hide | \
send ${url} | \
jq -r "(.stderr, .stdout, .code, .success)"
;;
format)
jo code="${code}" | \
send ${url} | \
jq -r "(.stderr, .stdout, .code, .success)"
;;
clippy)
jo code="${code}" | \
send ${url} | \
jq -r "(.stderr, .stdout, .success)"
;;
*)
echo ${usage}
exit 1
esac
# <<EOF
# {
# "channel":"stable",
# "mode":"debug",
# "crateType":"bin",
# "tests":false,
# "code":"fn main() {\n println!(\"Hello, world!\");\n}"
# }
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment