You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/a4.cargo-crates-and-basic-project-structure.md
+16-6
Original file line number
Diff line number
Diff line change
@@ -15,11 +15,11 @@ Cargo is Rust’s built-in package manager and build system. It also supports th
15
15
|`cargo build`| Build the executable |
16
16
|`cargo run`| Build the executable and run |
17
17
18
-
> 💡 The `cargo check` command verifies that the project compiles without errors, without producing an executable.
18
+
> 💡 The `cargo check` command verifies that the project compiles without errors, without producing an executable.
19
19
> Thus, it is often faster than `cargo build`.
20
20
21
-
> 💡 Cargo places executables compiled with `cargo build` or `cargo run` in the `target/debug/` directory.
22
-
> But, while those built with **`cargo build --release`** for release purposes are stored in `target/release/` directory.
21
+
> 💡 Cargo places executables compiled with `cargo build` or `cargo run` in the `target/debug/` directory.
22
+
> But, while those built with **`cargo build --release`** for release purposes are stored in `target/release/` directory.
23
23
> Release builds use more optimizations and remove some runtime safety checks to increase performance, although this comes at the cost of longer compile time.
24
24
25
25
| Command | Action |
@@ -55,7 +55,7 @@ In addition, there are `cargo` commands to publish the project as a crate to [cr
55
55
56
56
## Crate
57
57
58
-
- A crate is a package, which can be shared via Rust community’s crate registry, [crates.io](https://crates.io/).
58
+
- A crate is a package, which can be shared via Rust community’s crate registry, [crates.io](https://crates.io/).
59
59
60
60
- A crate can produce an executable or a library. In other words, it can be a **binary** crate or a **library** crate.
61
61
1.`cargo new crate_name --bin` or `cargo new crate_name`: Produces an executable
@@ -117,7 +117,17 @@ This is how [Cargo documentation describes](https://doc.rust-lang.org/cargo/guid
117
117
118
118
## Rust Editions
119
119
120
-
Rust guarantees backward compatibility while introducing major updates to the language. To support this, the `edition` field was added to the `Cargo.toml` file in Rust 2018, marking the first major update to the language ecosystem three years after its initial release. Editions are opt-in, meaning existing crates will not experience these changes until they explicitly migrate to the new edition.Rust guarantees backward compatibility between editions, allowing crates using older editions of Rust to interoperate seamlessly with those using newer versions.
120
+
Rust guarantees backward compatibility while introducing major updates to the language. To support this, the `edition` field was added to the `Cargo.toml` file in Rust 2018, marking the first major update to the language ecosystem three years after its initial release. Editions are opt-in, meaning existing crates will not experience these changes until they explicitly migrate to the new edition.
121
+
122
+
The major editions of Rust are:
123
+
124
+
-**Rust 2015**: The initial edition, introduced with Rust 1.0. It established the core language features like ownership, borrowing, and lifetimes, laying the foundation for Rust’s safety and concurrency guarantees.
125
+
126
+
-**Rust 2018**: The first major update, introduced the `edition` field in `Cargo.toml`, simplified the module system, stabilized `async`/`await`, improved error handling with the `?` operator, and made several syntactic changes.
127
+
128
+
-**Rust 2021**: Focused on improving ergonomics and removing inconsistencies, such as disjoint closure capture, `IntoIterator` for arrays, and the introduction of or-patterns in macros.
129
+
130
+
-**Rust 2024**: The latest edition, includes enhancements like refined `async` features, more `const` generics, better diagnostics, and improved Cargo features.
121
131
122
132
For new projects created by `cargo new`, it will set `edition = "2024"` by default in the `Cargo.toml` file. For example,
123
133
@@ -136,4 +146,4 @@ edition = "2024"
136
146
137
147
- Create an executable crate via `cargo new` command and run it via `cargo run`.
138
148
139
-
- Create a library crate via `cargo new` command and run `cargo test`.
149
+
- Create a library crate via `cargo new` command and run `cargo test`.
0 commit comments