1
- # Appendix D - Useful Development Tools
1
+ ## Appendix D - Useful Development Tools
2
2
3
3
In this appendix, we talk about some useful development tools that the Rust
4
4
project provides. We’ll look at automatic formatting, quick ways to apply
5
5
warning fixes, a linter, and integrating with IDEs.
6
6
7
- ## Automatic Formatting with ` rustfmt `
7
+ ### Automatic Formatting with ` rustfmt `
8
8
9
9
The ` rustfmt ` tool reformats your code according to the community code style.
10
10
Many collaborative projects use ` rustfmt ` to prevent arguments about which
11
11
style to use when writing Rust: everyone formats their code using the tool.
12
12
13
13
To install ` rustfmt ` , enter the following:
14
14
15
- ``` text
15
+ ``` console
16
16
$ rustup component add rustfmt
17
17
```
18
18
19
19
This command gives you ` rustfmt ` and ` cargo-fmt ` , similar to how Rust gives you
20
20
both ` rustc ` and ` cargo ` . To format any Cargo project, enter the following:
21
21
22
- ``` text
22
+ ``` console
23
23
$ cargo fmt
24
24
```
25
25
@@ -29,7 +29,7 @@ on `rustfmt`, see [its documentation][rustfmt].
29
29
30
30
[ rustfmt ] : https://github.com/rust-lang/rustfmt
31
31
32
- ## Fix Your Code with ` rustfix `
32
+ ### Fix Your Code with ` rustfix `
33
33
34
34
The rustfix tool is included with Rust installations and can automatically fix
35
35
some compiler warnings. If you’ve written code in Rust, you’ve probably seen
@@ -50,7 +50,7 @@ fn main() {
50
50
Here, we’re calling the ` do_something ` function 100 times, but we never use the
51
51
variable ` i ` in the body of the ` for ` loop. Rust warns us about that:
52
52
53
- ``` text
53
+ ``` console
54
54
$ cargo build
55
55
Compiling myprogram v0.1.0 (file:///projects/myprogram)
56
56
warning: unused variable: `i`
@@ -69,7 +69,7 @@ indicates that we intend for this variable to be unused. We can automatically
69
69
apply that suggestion using the ` rustfix ` tool by running the command `cargo
70
70
fix`:
71
71
72
- ``` text
72
+ ``` console
73
73
$ cargo fix
74
74
Checking myprogram v0.1.0 (file:///projects/myprogram)
75
75
Fixing src/main.rs (1 fix)
@@ -96,20 +96,20 @@ The `for` loop variable is now named `_i`, and the warning no longer appears.
96
96
You can also use the ` cargo fix ` command to transition your code between
97
97
different Rust editions. Editions are covered in Appendix E.
98
98
99
- ## More Lints with Clippy
99
+ ### More Lints with Clippy
100
100
101
- The Clippy tool is a collection of lints to analyze your code to catch common
102
- mistakes and improve your Rust code.
101
+ The Clippy tool is a collection of lints to analyze your code so you can catch
102
+ common mistakes and improve your Rust code.
103
103
104
104
To install Clippy, enter the following:
105
105
106
- ``` text
106
+ ``` console
107
107
$ rustup component add clippy
108
108
```
109
109
110
110
To run Clippy’s lints on any Cargo project, enter the following:
111
111
112
- ``` text
112
+ ``` console
113
113
$ cargo clippy
114
114
```
115
115
@@ -139,9 +139,9 @@ error: approximate value of `f{32, 64}::consts::PI` found. Consider using it dir
139
139
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/master/index.html#approx_constant
140
140
```
141
141
142
- This error lets you know that Rust has this constant defined more precisely,
143
- and that your program would be more correct if you used the constant instead.
144
- You would then change your code to use the ` PI ` constant. The following code
142
+ This error lets you know that Rust has this constant defined more precisely and
143
+ that your program would be more correct if you used the constant instead. You
144
+ would then change your code to use the ` PI ` constant. The following code
145
145
doesn’t result in any errors or warnings from Clippy:
146
146
147
147
<span class =" filename " >Filename: src/main.rs</span >
@@ -158,7 +158,7 @@ For more information on Clippy, see [its documentation][clippy].
158
158
159
159
[ clippy ] : https://github.com/rust-lang/rust-clippy
160
160
161
- ## IDE Integration Using the Rust Language Server
161
+ ### IDE Integration Using the Rust Language Server
162
162
163
163
To help IDE integration, the Rust project distributes the * Rust Language
164
164
Server* (` rls ` ). This tool speaks the [ Language Server
@@ -171,7 +171,7 @@ such as [the Rust plug-in for Visual Studio Code][vscode].
171
171
172
172
To install the ` rls ` , enter the following:
173
173
174
- ``` text
174
+ ``` console
175
175
$ rustup component add rls
176
176
```
177
177
0 commit comments