April 2026
Intermediate
631 pages
16h 20m
English
In this section, we’ll provide some practice questions to help reinforce your learning. The exercise questions cover almost all the concepts introduced in the chapter. Solutions to each exercise will follow in Section 5.8.
Storing different types in a vectorIn Rust, vectors are typically used to store elements of the same type. However, in some cases, you may want to store multiple data types in a single vector. The following code aims to store both integers and floats in a vector:
#[derive(Debug)]enum Value { // Add code here}fn main() { let some_val = vec![Value::Integer(12), Value::Float(15.5)]; for i in some_val { match i { Value::Integer(num) => println!("Integer: {} ", num), Value::Float(num) => println!("Float: ...
Read now
Unlock full access