Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'latest' instead of a version number.
Omitting the quotes around the version number.
✗ Incorrect
In Cargo.toml, dependencies are specified with their version numbers as strings, like "1.0".
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cargo build' or 'cargo run' instead of 'cargo add'.
Forgetting to specify the crate name.
✗ Incorrect
The command 'cargo add rand' adds the rand crate to your dependencies in Cargo.toml.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the feature name.
Using single quotes instead of double quotes.
✗ Incorrect
Features in Cargo.toml must be strings inside double quotes within the list.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using just the URL string without git key.
Specifying version instead of git for Git dependencies.
✗ Incorrect
To specify a Git dependency with a branch, use a table with git URL and branch name.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using underscores instead of hyphens in keys.
Setting default-features to true when it should be false.
✗ Incorrect
The correct syntax uses hyphens in keys: default-features and optional with proper boolean values.