Skip to content

Commit 39ebdd5

Browse files
committed
🦄 Upload docs
1 parent bc0391e commit 39ebdd5

File tree

39 files changed

+238
-100
lines changed

39 files changed

+238
-100
lines changed

docs/assets/css/docs.min.67fc7b3b41d707b198af1dd244ec62e1a1dd4665e40cb6f1d97e9257e597ff1d.css renamed to docs/assets/css/docs.min.a6d52fd5461b892ef08a611a76391f8b999c6aca8f2a2317d6827c1143c0ca03.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/borrowing/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<title>Borrowing · Learning Rust</title>
1414
<link rel="canonical" href="https://learning-rust.github.io/docs/borrowing/">
15-
<link rel="stylesheet" href="/assets/css/docs.min.67fc7b3b41d707b198af1dd244ec62e1a1dd4665e40cb6f1d97e9257e597ff1d.css" integrity="">
15+
<link rel="stylesheet" href="/assets/css/docs.min.a6d52fd5461b892ef08a611a76391f8b999c6aca8f2a2317d6827c1143c0ca03.css" integrity="">
1616

1717
<link rel="manifest" href="/manifest.json">
1818
<link rel="icon" href="/favicon/favicon.ico">

docs/docs/cargo-crates-and-basic-project-structure/index.html

Lines changed: 156 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<title>Cargo, Crates and Basic Project Structure · Learning Rust</title>
1414
<link rel="canonical" href="https://learning-rust.github.io/docs/cargo-crates-and-basic-project-structure/">
15-
<link rel="stylesheet" href="/assets/css/docs.min.67fc7b3b41d707b198af1dd244ec62e1a1dd4665e40cb6f1d97e9257e597ff1d.css" integrity="">
15+
<link rel="stylesheet" href="/assets/css/docs.min.a6d52fd5461b892ef08a611a76391f8b999c6aca8f2a2317d6827c1143c0ca03.css" integrity="">
1616

1717
<link rel="manifest" href="/manifest.json">
1818
<link rel="icon" href="/favicon/favicon.ico">
@@ -390,35 +390,148 @@ <h1>Cargo, Crates and Basic Project Structure</h1>
390390
</header>
391391
<div id="article-body">
392392
<h2 id="cargo">Cargo</h2>
393-
<p>Cargo is Rust’s built-in package manager and the build system. It can be used to,</p>
394-
<ul>
395-
<li>Create a new project: <code>cargo new</code></li>
396-
<li>Create a new project in an existing directory: <code>cargo init</code></li>
397-
<li>Build the project: <code>cargo build</code></li>
398-
<li>Run the project: <code>cargo run</code></li>
399-
<li>Update project dependencies: <code>cargo update</code></li>
400-
<li>Run tests: <code>cargo test</code></li>
401-
<li>Run benchmarks: <code>cargo bench</code></li>
402-
<li>Generate the project documentation via <a href="https://doc.rust-lang.org/stable/rustdoc/">rustdoc</a>: <code>cargo doc</code></li>
403-
<li>Analyze the project to see it has any errors, without building it: <code>cargo check</code></li>
404-
</ul>
405-
<p>In addition, there are <code>cargo</code> commands to publish the project as a crate/ package to <strong>Rust&rsquo;s official crate registry, <a href="https://crates.io/">crates.io</a></strong>.</p>
393+
<p>Cargo is Rust’s built-in package manager and build system. It also supports the following actions,</p>
394+
<table>
395+
<thead>
396+
<tr>
397+
<th>Command</th>
398+
<th>Action</th>
399+
</tr>
400+
</thead>
401+
<tbody>
402+
<tr>
403+
<td><code>cargo new</code></td>
404+
<td>Create a new project</td>
405+
</tr>
406+
<tr>
407+
<td><code>cargo init</code></td>
408+
<td>Create a new project in an existing directory</td>
409+
</tr>
410+
<tr>
411+
<td><code>cargo check</code></td>
412+
<td>Verify the project compiles without errors</td>
413+
</tr>
414+
<tr>
415+
<td><code>cargo build</code></td>
416+
<td>Build the executable</td>
417+
</tr>
418+
<tr>
419+
<td><code>cargo run</code></td>
420+
<td>Build the executable and run</td>
421+
</tr>
422+
</tbody>
423+
</table>
406424
<blockquote>
407-
<p>💡 We need to get an API token from <a href="https://crates.io/">crates.io</a> to publish a crate to it. The API token can be found in the <a href="https://crates.io/me">Account Settings page</a>, after login to that site. We will discuss more about this under <a href="/docs/crates#c-using-cratesio">code organization with crates</a>.</p>
425+
<p>💡 The <code>cargo check</code> command verifies that the project compiles without errors, without producing an executable.
426+
Thus, it is often faster than <code>cargo build</code>.</p>
427+
</blockquote>
428+
<blockquote>
429+
<p>💡 Cargo places executables compiled with <code>cargo build</code> or <code>cargo run</code> in the <code>target/debug/</code> directory.
430+
But, while those built with <strong><code>cargo build --release</code></strong> for release purposes are stored in <code>target/release/</code> directory.
431+
Release builds use more optimizations and remove some runtime safety checks to increase performance, although this comes at the cost of longer compile time.</p>
432+
</blockquote>
433+
<table>
434+
<thead>
435+
<tr>
436+
<th>Command</th>
437+
<th>Action</th>
438+
</tr>
439+
</thead>
440+
<tbody>
441+
<tr>
442+
<td><code>cargo add</code></td>
443+
<td>Add a dependency crate to the project</td>
444+
</tr>
445+
<tr>
446+
<td><code>cargo remove</code></td>
447+
<td>Remove a dependency crate from the project</td>
448+
</tr>
449+
<tr>
450+
<td><code>cargo fetch</code></td>
451+
<td>Download the dependencies specified in Cargo.lock</td>
452+
</tr>
453+
<tr>
454+
<td><code>cargo update</code></td>
455+
<td>Update project dependencies</td>
456+
</tr>
457+
</tbody>
458+
</table>
459+
<blockquote>
460+
<p>💡 A crate is a package that can be shared via <a href="https://crates.io">crates.io</a>, Rust community’s crate registry.
461+
<code>cargo add</code>, <code>cargo remove</code>, <code>cargo fetch</code>, and <code>cargo update</code> commands manage project dependencies through the crate hosted on crates.io.</p>
462+
</blockquote>
463+
<blockquote>
464+
<p>💡 The <code>cargo add</code> command includes a specified crate in the <code>[dependencies]</code> section of <code>Cargo.toml</code>, while <code>cargo add --dev</code> adds a crate to the <code>[dev-dependencies]</code> section. This indicates that the crate is only used for development purposes like testing and will not be included in the final compiled code.</p>
465+
</blockquote>
466+
<table>
467+
<thead>
468+
<tr>
469+
<th>Command</th>
470+
<th>Action</th>
471+
</tr>
472+
</thead>
473+
<tbody>
474+
<tr>
475+
<td><code>cargo test</code></td>
476+
<td>Run tests</td>
477+
</tr>
478+
<tr>
479+
<td><code>cargo bench</code></td>
480+
<td>Run benchmarks</td>
481+
</tr>
482+
<tr>
483+
<td><code>cargo doc</code></td>
484+
<td>Generate the project documentation via <a href="https://doc.rust-lang.org/stable/rustdoc/">rustdoc</a></td>
485+
</tr>
486+
</tbody>
487+
</table>
488+
<p>In addition, there are <code>cargo</code> commands to publish the project as a crate to <a href="https://crates.io/">crates.io</a>.</p>
489+
<table>
490+
<thead>
491+
<tr>
492+
<th>Command</th>
493+
<th>Action</th>
494+
</tr>
495+
</thead>
496+
<tbody>
497+
<tr>
498+
<td><code>cargo login</code></td>
499+
<td>Login to <a href="https://crates.io/">crates.io</a> with the API token</td>
500+
</tr>
501+
<tr>
502+
<td><code>cargo package</code></td>
503+
<td>Make the local crate uploadable to <a href="https://crates.io/">crates.io</a></td>
504+
</tr>
505+
<tr>
506+
<td><code>cargo publish</code></td>
507+
<td>Upload the crate to <a href="https://crates.io/">crates.io</a></td>
508+
</tr>
509+
<tr>
510+
<td><code>cargo install</code></td>
511+
<td>Install a Rust binary</td>
512+
</tr>
513+
<tr>
514+
<td><code>cargo uninstall</code></td>
515+
<td>Uninstall a Rust binary</td>
516+
</tr>
517+
</tbody>
518+
</table>
519+
<blockquote>
520+
<p>💡 You need to get an API token from <a href="https://crates.io/">crates.io</a> to publish a crate to it. The API token can be found in the <a href="https://crates.io/me">Account Settings page</a>, after login to that site. We will discuss more about this under <a href="/docs/crates#c-using-cratesio">code organization with crates</a>.</p>
408521
</blockquote>
409-
<ul>
410-
<li>Login to <a href="https://crates.io/">crates.io</a> with the API token: <code>cargo login</code></li>
411-
<li>Make the local crate uploadable to <a href="https://crates.io/">crates.io</a>: <code>cargo package</code></li>
412-
<li>Upload the crate to <a href="https://crates.io/">crates.io</a>: <code>cargo publish</code></li>
413-
<li>Install a Rust binary: <code>cargo install</code></li>
414-
<li>Uninstall a Rust binary: <code>cargo uninstall</code></li>
415-
</ul>
416522
<h2 id="crate">Crate</h2>
417-
<p>A crate is a package, which can be shared via <a href="https://crates.io/">crates.io</a>. A crate can produce an executable or a library. In other words, it can be a <strong>binary</strong> crate or a <strong>library</strong> crate.</p>
523+
<ul>
524+
<li>
525+
<p>A crate is a package, which can be shared via Rust community’s crate registry, <a href="https://crates.io/">crates.io</a>.</p>
526+
</li>
527+
<li>
528+
<p>A crate can produce an executable or a library. In other words, it can be a <strong>binary</strong> crate or a <strong>library</strong> crate.</p>
418529
<ol>
419530
<li><code>cargo new crate_name --bin</code> or <code>cargo new crate_name</code>: Produces an executable</li>
420531
<li><code>cargo new crate_name --lib</code>: Produces a library</li>
421532
</ol>
533+
</li>
534+
</ul>
422535
<p>The first one generates,</p>
423536
<pre tabindex="0"><code>├── Cargo.toml
424537
└── src
@@ -432,9 +545,6 @@ <h2 id="crate">Crate</h2>
432545
<li><strong>src</strong> folder is the place to store the source code.</li>
433546
<li>Each crate has an implicit crate root/ entry point. <strong>main.rs</strong> is the crate root for a binary crate and <strong>lib.rs</strong> is the crate root for a library crate.</li>
434547
</ul>
435-
<blockquote>
436-
<p>💡 When we build a binary crate via <code>cargo build</code> or <code>cargo run</code>, the executable file will be stored in the <strong>target/debug/</strong> folder. But when building it via <strong><code>cargo build --release</code></strong> for a release it will be stored in the <strong>target/release/</strong> folder. The release builds are applying more optimizations while compiling the code, to make the code run faster. But it takes more compile time.</p>
437-
</blockquote>
438548
<h2 id="project-structure">Project Structure</h2>
439549
<p>This is how <a href="https://doc.rust-lang.org/cargo/guide/project-layout.html">Cargo documentation describes</a> about the recommended project layout,</p>
440550
<pre tabindex="0"><code>.
@@ -444,7 +554,10 @@ <h2 id="project-structure">Project Structure</h2>
444554
│ ├── main.rs
445555
│ ├── lib.rs
446556
│ └── bin
447-
│ └── another_executable.rs
557+
│ ├── another_executable.rs
558+
│ └── multi_file_executable
559+
│ ├── main.rs
560+
│ └── some_module.rs
448561
├── tests
449562
│ └── some_integration_tests.rs
450563
├── benches
@@ -456,20 +569,30 @@ <h2 id="project-structure">Project Structure</h2>
456569
<ul>
457570
<li>The default executable file is <code>src/main.rs</code>.</li>
458571
<li>The default library file is <code>src/lib.rs</code>.</li>
459-
<li>Other executables can be placed in <code>src/bin/*.rs</code>.</li>
572+
<li>Other executables can be placed in,
573+
<ul>
574+
<li><code>src/bin/*.rs</code></li>
575+
<li><code>src/bin/*/main.rs</code></li>
576+
</ul>
577+
</li>
460578
</ul>
461579
</li>
462580
<li>Integration tests go in the <code>tests</code> directory (unit tests go in each file they&rsquo;re testing).</li>
463581
<li>Benchmarks go in the <code>benches</code> directory.</li>
464582
<li>Examples go in the <code>examples</code> directory.</li>
465583
</ul>
466584
<h2 id="rust-editions">Rust Editions</h2>
467-
<p>After the initial release in 2015, according to the feedback got from user communities, the Rust team was focusing to increase the <strong>productivity</strong> of the language and the ecosystem. After 3 years of hard work in 2018, a new Rust edition was released with new features, simplified syntax and better tooling. We call it <strong>Rust 2018</strong> edition.</p>
468-
<p>To keep the promise of supporting backward compatibility, the new <code>edition = &quot;2018&quot;</code> configuration was added to the <code>Cargo.toml</code> file. For new projects, the <code>cargo new</code> command adds this configuration by default. So, you don&rsquo;t need to care. But on legacy crates, if you can not see any <code>edition</code> configuration, Cargo will consider it as a Rust 2015 edition crate.</p>
469-
<h2 id="-before-going-to-the-next">👨‍🏫 Before going to the next&hellip;</h2>
585+
<p>The language has seen a series of improvements every three years through new editions since its initial stable release in 2015, including the initial version, <strong>Rust 2015</strong>, followed by <strong>Rust 2018</strong>, and the latest, <strong>Rust 2021</strong>.</p>
586+
<p>The <code>edition</code> key in the <code>Cargo.toml</code> file denotes the edition of the Rust compiler to be used for compiling the crate. Editions are opt-in, meaning existing crates will not see 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.</p>
587+
<p>For new projects created by <code>cargo new</code>, it will set <code>edition = &quot;2021&quot;</code> by default in the <code>Cargo.toml</code> file. For example,</p>
588+
<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>
589+
</span></span><span class="line"><span class="cl"><span class="nx">name</span> <span class="p">=</span> <span class="s2">&#34;api&#34;</span>
590+
</span></span><span class="line"><span class="cl"><span class="nx">version</span> <span class="p">=</span> <span class="s2">&#34;0.1.0&#34;</span>
591+
</span></span><span class="line"><span class="cl"><span class="nx">edition</span> <span class="p">=</span> <span class="s2">&#34;2021&#34;</span>
592+
</span></span></code></pre></div><h2 id="-before-going-to-the-next">👨‍🏫 Before going to the next&hellip;</h2>
470593
<ul>
471594
<li>
472-
<p>The <strong><code>.cargo/bin</code> directory of your home directory</strong> is the default location of Rust binaries. Not only the official binaries like <code>rustup</code>, <code>rustc</code>, <code>cargo</code>, <code>rustfmt</code>, <code>rustdoc</code>, <code>rls</code> and also the binaries you can install via <code>cargo install</code> command, will be stored in this directory.</p>
595+
<p>The <code>.cargo/bin</code> directory of your home directory is the default location of Rust binaries. Not only the official binaries like <code>rustc</code>, <code>cargo</code>, <code>rustup</code>, <code>rustfmt</code>, <code>rustdoc</code>, <code>rust-analyzer</code> and also the binaries you can install via <code>cargo install</code> command, will be stored in this directory.</p>
473596
</li>
474597
<li>
475598
<p>Even though the initial convention for naming crates and file names is using the <a href="https://en.wikipedia.org/wiki/Snake_case"><code>snake_case</code></a>, some crate developers are using <code>kebab-case</code> on both crates and file names. To make your code more consistent, use the initial convention <code>snake_case</code>; especially on file names.</p>
@@ -544,7 +667,7 @@ <h2 id="-before-going-to-the-next">👨‍🏫 Before going to the next&hellip;<
544667

545668

546669

547-
<time datetime="2023-11-11"><i>🕒</i> Updated: 2023-11-11</time>
670+
<time datetime="2024-03-10"><i>🕒</i> Updated: 2024-03-10</time>
548671

549672
<a href="/docs/hello-world/"><i></i> Previous</a>
550673

docs/docs/code-organization/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<title>Code Organization · Learning Rust</title>
1414
<link rel="canonical" href="https://learning-rust.github.io/docs/code-organization/">
15-
<link rel="stylesheet" href="/assets/css/docs.min.67fc7b3b41d707b198af1dd244ec62e1a1dd4665e40cb6f1d97e9257e597ff1d.css" integrity="">
15+
<link rel="stylesheet" href="/assets/css/docs.min.a6d52fd5461b892ef08a611a76391f8b999c6aca8f2a2317d6827c1143c0ca03.css" integrity="">
1616

1717
<link rel="manifest" href="/manifest.json">
1818
<link rel="icon" href="/favicon/favicon.ico">

docs/docs/combinators/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<title>Combinators · Learning Rust</title>
1414
<link rel="canonical" href="https://learning-rust.github.io/docs/combinators/">
15-
<link rel="stylesheet" href="/assets/css/docs.min.67fc7b3b41d707b198af1dd244ec62e1a1dd4665e40cb6f1d97e9257e597ff1d.css" integrity="">
15+
<link rel="stylesheet" href="/assets/css/docs.min.a6d52fd5461b892ef08a611a76391f8b999c6aca8f2a2317d6827c1143c0ca03.css" integrity="">
1616

1717
<link rel="manifest" href="/manifest.json">
1818
<link rel="icon" href="/favicon/favicon.ico">

docs/docs/comments-and-documenting-the-code/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<title>Comments and Documenting the code · Learning Rust</title>
1414
<link rel="canonical" href="https://learning-rust.github.io/docs/comments-and-documenting-the-code/">
15-
<link rel="stylesheet" href="/assets/css/docs.min.67fc7b3b41d707b198af1dd244ec62e1a1dd4665e40cb6f1d97e9257e597ff1d.css" integrity="">
15+
<link rel="stylesheet" href="/assets/css/docs.min.a6d52fd5461b892ef08a611a76391f8b999c6aca8f2a2317d6827c1143c0ca03.css" integrity="">
1616

1717
<link rel="manifest" href="/manifest.json">
1818
<link rel="icon" href="/favicon/favicon.ico">

docs/docs/control-flows/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<title>Control Flows · Learning Rust</title>
1414
<link rel="canonical" href="https://learning-rust.github.io/docs/control-flows/">
15-
<link rel="stylesheet" href="/assets/css/docs.min.67fc7b3b41d707b198af1dd244ec62e1a1dd4665e40cb6f1d97e9257e597ff1d.css" integrity="">
15+
<link rel="stylesheet" href="/assets/css/docs.min.a6d52fd5461b892ef08a611a76391f8b999c6aca8f2a2317d6827c1143c0ca03.css" integrity="">
1616

1717
<link rel="manifest" href="/manifest.json">
1818
<link rel="icon" href="/favicon/favicon.ico">

docs/docs/crates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<title>Crates · Learning Rust</title>
1414
<link rel="canonical" href="https://learning-rust.github.io/docs/crates/">
15-
<link rel="stylesheet" href="/assets/css/docs.min.67fc7b3b41d707b198af1dd244ec62e1a1dd4665e40cb6f1d97e9257e597ff1d.css" integrity="">
15+
<link rel="stylesheet" href="/assets/css/docs.min.a6d52fd5461b892ef08a611a76391f8b999c6aca8f2a2317d6827c1143c0ca03.css" integrity="">
1616

1717
<link rel="manifest" href="/manifest.json">
1818
<link rel="icon" href="/favicon/favicon.ico">

docs/docs/custom-error-types/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<title>Custom Error Types · Learning Rust</title>
1414
<link rel="canonical" href="https://learning-rust.github.io/docs/custom-error-types/">
15-
<link rel="stylesheet" href="/assets/css/docs.min.67fc7b3b41d707b198af1dd244ec62e1a1dd4665e40cb6f1d97e9257e597ff1d.css" integrity="">
15+
<link rel="stylesheet" href="/assets/css/docs.min.a6d52fd5461b892ef08a611a76391f8b999c6aca8f2a2317d6827c1143c0ca03.css" integrity="">
1616

1717
<link rel="manifest" href="/manifest.json">
1818
<link rel="icon" href="/favicon/favicon.ico">

docs/docs/enums/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<title>Enums · Learning Rust</title>
1414
<link rel="canonical" href="https://learning-rust.github.io/docs/enums/">
15-
<link rel="stylesheet" href="/assets/css/docs.min.67fc7b3b41d707b198af1dd244ec62e1a1dd4665e40cb6f1d97e9257e597ff1d.css" integrity="">
15+
<link rel="stylesheet" href="/assets/css/docs.min.a6d52fd5461b892ef08a611a76391f8b999c6aca8f2a2317d6827c1143c0ca03.css" integrity="">
1616

1717
<link rel="manifest" href="/manifest.json">
1818
<link rel="icon" href="/favicon/favicon.ico">

0 commit comments

Comments
 (0)