Search code examples
visual-studio-coderustrust-cargo

How to run cargo fmt on save in vscode?


Is it possible to make Visual Studio Code run cargo fmt on file save?


Solution

  • Install the extension rust-analyzer (the officially recommended vscode extension), and add the following to settings.json:

    "[rust]": {
        "editor.defaultFormatter": "rust-lang.rust-analyzer",
        "editor.formatOnSave": true
    }