0
0
Rustprogramming~5 mins

Using external crates in Rust - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a crate in Rust?
A crate is a package of Rust code. It can be a library or a binary. Crates help organize and share code.
Click to reveal answer
beginner
How do you add an external crate to your Rust project?
You add the crate name and version to the [dependencies] section in the Cargo.toml file.
Click to reveal answer
beginner
What command downloads and compiles external crates listed in Cargo.toml?
The command cargo build downloads and compiles all dependencies including external crates.
Click to reveal answer
beginner
How do you use an external crate in your Rust code after adding it to Cargo.toml?
You add use crate_name::module; at the top of your Rust file to bring the crate's code into scope.
Click to reveal answer
intermediate
What is the purpose of extern crate in Rust?
In modern Rust editions, extern crate is mostly optional. It was used to link external crates before the 2018 edition.
Click to reveal answer
Where do you specify external crates for a Rust project?
AIn the .rs source files using #include
BIn the main.rs file
CIn the rustc compiler flags
DIn the Cargo.toml file under [dependencies]
Which command downloads and compiles external crates?
Acargo build
Bcargo run
Crustc main.rs
Dcargo test
How do you bring an external crate into scope in your Rust code?
Aimport crate_name;
B#include <crate_name>
Cuse crate_name::module;
Dextern crate crate_name;
Is extern crate still required in Rust 2021 edition?
AYes, always required
BNo, it is mostly optional now
COnly for standard library crates
DOnly for crates from crates.io
What file manages dependencies in a Rust project?
ACargo.toml
Bmain.rs
Clib.rs
Drustc.toml
Explain the steps to add and use an external crate in a Rust project.
Think about where you declare, how you get it, and how you use it.
You got /3 concepts.
    What is the role of Cargo in managing external crates?
    Cargo is like the project helper for Rust.
    You got /4 concepts.