Skip to content

Instantly share code, notes, and snippets.

@ryochack
Created April 20, 2018 06:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryochack/48ebf4558ce1f1daae3cdfc2160a4dba to your computer and use it in GitHub Desktop.
Save ryochack/48ebf4558ce1f1daae3cdfc2160a4dba to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
# Usage:
#
# $ rustinstant 'println!("hello world!")'
# => hello world
#
# or
#
# $ cat << EOF | rustinstant
# > println!("hello world!");
# > EOF
# => hello world
set -eu
function fn_run_rust() {
echo "fn main() { $* }" | rustc - && ./rust_out
}
if [ -p /dev/stdin ]; then
code=$(cat -)
elif [ $# -gt 0 ]; then
code=$1
else
echo "rustinstant failed"
exit 1
fi
fn_run_rust $code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment