+</code></pre><ul><li>The source code goes in the <code>src</code> directory.<ul><li>The default executable file is <code>src/main.rs</code>.</li><li>The default library file is <code>src/lib.rs</code>.</li><li>Other executables can be placed in,<ul><li><code>src/bin/*.rs</code></li><li><code>src/bin/*/main.rs</code></li></ul></li></ul></li><li>Integration tests go in the <code>tests</code> directory (unit tests go in each file they’re testing).</li><li>Benchmarks go in the <code>benches</code> directory.</li><li>Examples go in the <code>examples</code> directory.</li></ul><h2 id=rust-editions>Rust Editions</h2><p>Rust guarantees backward compatibility while introducing major updates to the language. To support this, the <code>edition</code> field was added to the <code>Cargo.toml</code> 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.</p><p>The major editions of Rust are:</p><ul><li><p><strong>Rust 2015</strong>: 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.</p></li><li><p><strong>Rust 2018</strong>: The first major update, introduced the <code>edition</code> field in <code>Cargo.toml</code>, simplified the module system, stabilized <code>async</code>/<code>await</code>, improved error handling with the <code>?</code> operator, and made several syntactic changes.</p></li><li><p><strong>Rust 2021</strong>: Focused on improving ergonomics and removing inconsistencies, such as disjoint closure capture, <code>IntoIterator</code> for arrays, and the introduction of or-patterns in macros.</p></li><li><p><strong>Rust 2024</strong>: The latest edition, includes enhancements like refined <code>async</code> features, more <code>const</code> generics, better diagnostics, and improved Cargo features.</p></li></ul><p>For new projects created by <code>cargo new</code>, it will set <code>edition = "2024"</code> by default in the <code>Cargo.toml</code> file. For example,</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-toml data-lang=toml><span class=line><span class=cl><span class=p>[</span><span class=nx>package</span><span class=p>]</span>
0 commit comments