Skip to content

Instantly share code, notes, and snippets.

@kosh04
Created February 6, 2018 15:56
Show Gist options
  • Save kosh04/99da55a8a877013abf5328b100f6c64c to your computer and use it in GitHub Desktop.
Save kosh04/99da55a8a877013abf5328b100f6c64c to your computer and use it in GitHub Desktop.
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