Complete the code to print "Hello, Rust!" to the console.
fn main() {
println!([1]);
}The println! macro requires a string literal inside double quotes to print text.
Complete the code to declare a variable named age with the value 30.
fn main() {
let [1] = 30;
}let again inside the blankvar which is not Rust syntaxconst which requires a typeIn Rust, let declares a variable, so only the variable name age goes after let.
Fix the error in the function signature to accept a string slice parameter named name.
fn greet([1]: &str) { println!("Hello, {}!", name); }
String instead of &str&name which is invalid syntaxThe function parameter must include the name and its type. Here, name: &str means a string slice named name.
Fill both blanks to create a vector of numbers from 1 to 5 and print its length.
fn main() {
let mut numbers = Vec::[1]();
for i in 1..=[2] {
numbers.push(i);
}
println!("Length: {}", numbers.len());
}with_capacity without a numberVec::new() creates an empty vector. The loop runs from 1 to 5 to add numbers.
Fill all three blanks to create a hash map, insert a key-value pair, and print the value for the key.
use std::collections::HashMap;
fn main() {
let mut map = HashMap::[1]();
map.[2]("color", "blue");
println!("Color: {}", map.get("color").[3]());
}push which is not a HashMap methodgetHashMap::new() creates a new map. insert adds a key-value pair. unwrap() gets the value from the Option.