set -euo pipefail
echo "[pre-commit] Running cargo fmt --all"
cargo fmt --all
mapfile -t staged_rs_files < <(git diff --cached --name-only --diff-filter=ACMR -- '*.rs')
if [ "${#staged_rs_files[@]}" -gt 0 ]; then
git add -- "${staged_rs_files[@]}"
fi