保存时运行fmt

"[rust]": {
    "editor.defaultFormatter": "rust-lang.rust-analyzer",
    "editor.formatOnSave": true
}
  1. Install rust-analyzer, if you have not already.
  2. In Visual Studio Code's settings, enable Editor: Format On Save (editor.formatOnSave).