0
0
Rustprogramming~10 mins

Cargo dependency management in Rust - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a dependency on the "serde" crate in Cargo.toml.

Rust
[dependencies]
serde = "[1]"
Drag options to blanks, or click blank then click option'
Alatest
B1.0
Cversion
Dcargo
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'latest' instead of a version number.
Omitting the quotes around the version number.
2fill in blank
medium

Complete the command to add the "rand" crate as a dependency using Cargo CLI.

Rust
cargo [1] rand
Drag options to blanks, or click blank then click option'
Arun
Bbuild
Cadd
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cargo build' or 'cargo run' instead of 'cargo add'.
Forgetting to specify the crate name.
3fill in blank
hard

Fix the error in the Cargo.toml snippet to specify a dependency with features.

Rust
[dependencies]
regex = { version = "1", features = [[1]] }
Drag options to blanks, or click blank then click option'
A"std"
B'std'
Cstd
Dstd_feature
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the feature name.
Using single quotes instead of double quotes.
4fill in blank
hard

Fill both blanks to specify a dependency from a Git repository with a branch.

Rust
[dependencies]
mycrate = [1]
Drag options to blanks, or click blank then click option'
A"https://github.com/user/mycrate.git"
B{ version = "0.1" }
C{ path = "../mycrate" }
D{ git = "https://github.com/user/mycrate.git", branch = "main" }
Attempts:
3 left
💡 Hint
Common Mistakes
Using just the URL string without git key.
Specifying version instead of git for Git dependencies.
5fill in blank
hard

Fill all three blanks to specify an optional dependency with default features disabled and a specific version.

Rust
[dependencies]
serde_json = [1]
Drag options to blanks, or click blank then click option'
A{ version = "1.0", default-features = false, optional = true }
B{ version = "1.0", default_features = false, optional = true }
C{ version = "1.0", default-features = true, optional = false }
D{ version = "1.0", default_features = true, optional = false }
Attempts:
3 left
💡 Hint
Common Mistakes
Using underscores instead of hyphens in keys.
Setting default-features to true when it should be false.