Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Creating a new project": add example using 'cargo new --edition YEAR' #279

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions src/editions/creating-a-new-project.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Creating a new project

When you create a new project with Cargo, it will automatically add
configuration for the latest edition:
A new project created with Cargo is configured to use the latest edition by
default:

```console
> cargo new foo
$ cargo new foo
Created binary (application) `foo` project
> cat foo/Cargo.toml
$ cat foo/Cargo.toml
[package]
name = "foo"
version = "0.1.0"
Expand All @@ -15,11 +15,41 @@ edition = "2021"
[dependencies]
```

That `edition = "2021"` setting will configure your package to use Rust 2021.
No more configuration needed!
That `edition = "2021"` setting configures your package to be built using the
Rust 2021 edition. No further configuration needed!

If you'd prefer to use an older edition, you can change the value in that
key, for example:
You can use the `--edition <YEAR>` option of `cargo new` to create the project
using some specific edition. For example, creating a new project to use the
Rust 2018 edition could be done like this:

```console
$ cargo new --edition 2018 foo
Created binary (application) `foo` project
$ cat foo/Cargo.toml
[package]
name = "foo"
version = "0.1.0"
edition = "2018"

[dependencies]
```

Don't worry about accidentally using an invalid year for the edition; the
`cargo new` invocation will not accept an invalid edition year value:

```console
$ cargo new --edition 2019 foo
error: "2019" isn't a valid value for '--edition <YEAR>'
[possible values: 2015, 2018, 2021]

Did you mean "2018"?

For more information try --help
```

You can change the value of the `edition` key by simply editing the
`Cargo.toml` file. For example, to cause your package to be built using the
Rust 2015 edition, you would set the key as in the following example:

```toml
[package]
Expand All @@ -29,5 +59,3 @@ edition = "2015"

[dependencies]
```

This will build your package in Rust 2015.