0
0
Rustprogramming~10 mins

Type inference 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 declare a variable with inferred type.

Rust
let x = [1];
Drag options to blanks, or click blank then click option'
A42
B"hello"
Ctrue
Dlet
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a keyword like 'let' instead of a value.
Putting the value in quotes when it should be a number.
2fill in blank
medium

Complete the code to declare a variable with inferred string slice type.

Rust
let greeting = [1];
Drag options to blanks, or click blank then click option'
A42
B"hello"
C'c'
Dtrue
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using single quotes which denote a character, not a string.
Assigning a number instead of a string.
3fill in blank
hard

Fix the error in the code by completing the variable assignment with correct inferred type.

Rust
let is_active = [1];
Drag options to blanks, or click blank then click option'
Atrue
B1
C"true"
D't'
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a string "true" instead of boolean true.
Using a number or character instead of boolean.
4fill in blank
hard

Fill both blanks to create a vector with inferred type and print its length.

Rust
let numbers = vec![[1]];
println!("Length: {}", numbers.[2]());
Drag options to blanks, or click blank then click option'
A1, 2, 3
Blen
Dpush
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using push instead of len to get length.
Not providing elements inside vec![].
5fill in blank
hard

Fill all three blanks to create a hashmap with inferred types and check if a key exists.

Rust
use std::collections::HashMap;

let mut scores = HashMap::new();
scores.insert([1], [2]);
let has_key = scores.[3](&"Blue");
Drag options to blanks, or click blank then click option'
A"Blue"
B10
Ccontains_key
Dget
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using get instead of contains_key to check existence.
Using a number as a key instead of a string.