# Use Nix, if it's around, to get rustup
if [ -x "$(command -v nix-shell)" ]; then
  use nix -s shell.nix -w Pipfile
else
  # Check whether rustup is around and install it otherwise
  if ! [ -x "$(command -v rustup)" ]; then
    # Install
    # * silently (-y)
    # * without modifying PATH (--no-modify-path)
    # * installing the nightly toolchain (PyO3 requires at least 1.34.0-nightly 2019-02-06)
    curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain nightly
    # Add to PATH
    source "$HOME"/.cargo/env
    # Install RLS for code completion
    rustup component add rls-preview rust-analysis rust-src rustfmt-preview
  fi
fi
