Rust Tooling
In this step, we will set up common Rust developer tooling to help you have the best experience working on this project.
rustfmt
To keep your code clean and easy to read, we use a tool called rustfmt. To access all the latest features of rustfmt we specifically use the nightly toolchain.
To install rustfmt for nightly:
rustup component add rustfmt --toolchain nightly
To configure the behavior of rustfmt, we will create a rustfmt.toml file:
-
Create a new file in your project’s root directory called
rustfmt.toml.touch rustfmt.toml -
Use the provided
rustfmt.tomlfile to configure your formatting preferences. -
Run the code formatter using the following command:
cargo +nightly fmt
You may see minor formatting changes (such as indentation switching to tabs) based on the rustfmt.toml configuration. As you write more code, you will be able to see cargo +nightly fmt make everything look pretty, consistent, and easy to read.
We recommend you run
cargo +nightly fmtafter every step!
Rust Analyzer
Another popular tool in the Rust community is Rust Analyzer.
It provides many features like code completion and goto definition for code editors like VS Code.
However, to provide the full functionality that it does, Rust Analyzer needs to compile your code. For a small project like this one, this is not a problem, however working with a large project like the Polkadot SDK, it is.
It is my personal recommendation that Rust Analyzer is not needed in this workshop, and generally you should not use it for Substrate development. However, this section might be updated to include special configurations of Rust Analyzer which will work well with Polkadot SDK in the future.
However, if you would like to use it anyway, now is the right time to set it up.