Skip to content

「新しいプロジェクトを作成する」を更新 #81

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
75 changes: 56 additions & 19 deletions src/editions/creating-a-new-project.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,89 @@
<!--
# 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:
-->

# 新しいプロジェクトを作成する

Cargoは新たなプロジェクトを作成する際に自動で最新のエディションをコンフィギュレーションに追加します
Cargo で新たなプロジェクトを作成すると、最新のエディションを使う設定が自動的に記述されます

```console
> cargo +nightly new foo
Created binary (application) `foo` project
> cat foo/Cargo.toml
$ cargo new foo
Creating binary (application) `foo` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
$ cat foo/Cargo.toml
[package]
name = "foo"
version = "0.1.0"
authors = ["your name <[email protected]>"]
edition = "2021"
edition = "2024"

[dependencies]
```

<!--
That `edition = "2021"` setting will configure your package to use Rust 2021.
No more configuration needed!
That `edition = "2024"` setting configures your package to be built using the
Rust 2024 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:
-->

この `edition = "2021"` によってあなたのパッケージが Rust 2021 を利用するように設定されます
`edition = "2024"` で、パッケージが Rust 2024 でビルドされるよう設定されます
これ以外は必要ありません。

もし、他の古いエディションを使いたい場合は、その設定の値を変更できます。例えば、
`cargo new` のオプションとして `--edition <YEAR>` を用いれば、
新しいプロジェクトがそのエディションを使うようにできます。
たとえば、Rust 2018 を使ったプロジェクトを作るには、以下のようにします。

```toml
```console
$ cargo new --edition 2018 foo
Creating binary (application) `foo` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
$ cat foo/Cargo.toml
[package]
name = "foo"
version = "0.1.0"
authors = ["your name <[email protected]>"]
edition = "2015"
edition = "2018"

[dependencies]
```

<!--
This will build your package in Rust 2015.
Don't worry about accidentally using an invalid year for the edition; the
`cargo new` invocation will not accept an invalid edition year value:
-->

うっかり存在しないエディションを指定しても大丈夫です。
`cargo new` に存在しないエディションを指定しても弾かれます。

```console
$ cargo new --edition 2019 foo
error: invalid value '2019' for '--edition <YEAR>'
[possible values: 2015, 2018, 2021, 2024]

tip: a similar value exists: '2021'

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:
-->

とすると、あなたのパッケージは Rust 2015 でビルドされます。
`Cargo.toml` の `edition` の値を直接変更しても構いません。
たとえば、パッケージが Rust 2015 でビルドされるようにするには、以下のように設定すればよいです。

```toml
[package]
name = "foo"
version = "0.1.0"
authors = ["your name <[email protected]>"]
edition = "2015"

[dependencies]
```