add links to the 'Modules and Crates' node in the Rust roadmap (#5797)
parent
03bf058dd7
commit
5a23d4d326
5 changed files with 24 additions and 6 deletions
@ -1,3 +1,8 @@ |
||||
# Code Organization and Namespacing |
||||
|
||||
In Rust, the fundamental structure for organizing your code is through using a **module** system and **crates**. A module in Rust allows grouping of related function definitions and struct definitions in a named scope. It’s defined using the `mod` keyword. The modules can also be nested and make code more concise, readable, and manageable. On the other hand, a **crate** is a binary or a library project in Rust. It's the largest compilation unit of Rust. It's a tree of modules that produces a library or executable. The crate root is a source file which the Rust compiler starts from and makes up the root module of your crate (e.g. `main.rs` or `lib.rs`). |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [Rust by Example: Modules](https://doc.rust-lang.org/rust-by-example/mod.html) |
||||
- [The Rust Reference: Namespaces](https://doc.rust-lang.org/reference/names/namespaces.html) |
||||
|
@ -1,3 +1,8 @@ |
||||
# Dependency Management with Cargo.toml |
||||
|
||||
Dependency management in Rust is handled by a tool called Cargo. Cargo helps you manage your Rust projects, providing functionalities for building your code, downloading the libraries your project depends on, and building those libraries. These libraries are called *crates*. A crate is a package of Rust code. In your `Cargo.toml`, you list your dependencies in a [dependencies] section. You list libraries from crates.io by their name and version number. Cargo understands Semantic Versioning, a standard for writing version numbers. |
||||
Dependency management in Rust is handled by a tool called Cargo. Cargo helps you manage your Rust projects, providing functionalities for building your code, downloading the libraries your project depends on, and building those libraries. These libraries are called _crates_. A crate is a package of Rust code. In your `Cargo.toml`, you list your dependencies in a [dependencies] section. You list libraries from crates.io by their name and version number. Cargo understands Semantic Versioning, a standard for writing version numbers. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [Rust Blog: Cargo](https://blog.rust-lang.org/2016/05/05/cargo-pillars.html) |
||||
- [Rust by Example: Dependencies](https://doc.rust-lang.org/rust-by-example/cargo/deps.html) |
||||
|
@ -1,3 +1,7 @@ |
||||
# Publishing to crates.io |
||||
# Publishing on crates.io |
||||
|
||||
Publishing in Rust involves packaging up your library or executable and making it available for others to use. To publish a crate, you'll need to create an account on [crates.io](https://crates.io/), the Rust package repository. If you haven't already, you'll need to format your project in a specific way, detailing needed information in a `Cargo.toml` file. Then, use the command `cargo publish` to upload your crate to the registry. Updates to your crate can be published with the same command, but be mindful that crates.io does not allow you to delete or overwrite an existing version of a crate. Make sure that everything is in order before you publish! |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [The Cargo Book: Publishing on crates.io](https://doc.rust-lang.org/cargo/reference/publishing.html) |
||||
|
@ -1,3 +1,7 @@ |
||||
# Modules and Crates |
||||
|
||||
In Rust, a module is a namespace that contains definitions of functions or types. You can choose to make the definitions visible in other modules or not. This provides a method of encapsulation for your code. On the other hand, a crate is a binary or library. It is the smallest unit of compilation in Rust. A crate can link to other crates, and it is composed of many modules. Therefore, the module system allows for code organization within a crate, and the crate system allows for building and sharing functionality among multiple projects. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [Rust Book: Managing Growing Projects with Packages, Crates, and Modules](https://doc.rust-lang.org/book/ch07-00-managing-growing-projects-with-packages-crates-and-modules.html) |
||||
|
Loading…
Reference in new issue