1
1
# Creating a new project
2
2
3
- When you create a new project with Cargo, it will automatically add
4
- configuration for the latest edition :
3
+ A new project created with Cargo is configured to use the latest edition by
4
+ default :
5
5
6
6
``` console
7
- > cargo new foo
7
+ $ cargo new foo
8
8
Created binary (application) `foo` project
9
- > cat foo/Cargo.toml
9
+ $ cat foo/Cargo.toml
10
10
[package]
11
11
name = "foo"
12
12
version = "0.1.0"
@@ -15,11 +15,41 @@ edition = "2021"
15
15
[dependencies]
16
16
```
17
17
18
- That ` edition = "2021" ` setting will configure your package to use Rust 2021.
19
- No more configuration needed!
18
+ That ` edition = "2021" ` setting configures your package to be built using the
19
+ Rust 2021 edition. No further configuration needed!
20
20
21
- If you'd prefer to use an older edition, you can change the value in that
22
- key, for example:
21
+ You can use the ` --edition <YEAR> ` option of ` cargo new ` to create the project
22
+ using some specific edition. For example, creating a new project to use the
23
+ Rust 2018 edition could be done like this:
24
+
25
+ ``` console
26
+ $ cargo new --edition 2018 foo
27
+ Created binary (application) `foo` project
28
+ $ cat foo/Cargo.toml
29
+ [package]
30
+ name = "foo"
31
+ version = "0.1.0"
32
+ edition = "2018"
33
+
34
+ [dependencies]
35
+ ```
36
+
37
+ Don't worry about accidentally using an invalid year for the edition; the
38
+ ` cargo new ` invocation will not accept an invalid edition year value:
39
+
40
+ ``` console
41
+ $ cargo new --edition 2019 foo
42
+ error: "2019" isn't a valid value for '--edition <YEAR>'
43
+ [possible values: 2015, 2018, 2021]
44
+
45
+ Did you mean "2018"?
46
+
47
+ For more information try --help
48
+ ```
49
+
50
+ You can change the value of the ` edition ` key by simply editing the
51
+ ` Cargo.toml ` file. For example, to cause your package to be built using the
52
+ Rust 2015 edition, you would set the key as in the following example:
23
53
24
54
``` toml
25
55
[package ]
@@ -29,5 +59,3 @@ edition = "2015"
29
59
30
60
[dependencies ]
31
61
```
32
-
33
- This will build your package in Rust 2015.
0 commit comments