April 2026
Intermediate
631 pages
16h 20m
English
This section provides the code solutions for the practice exercises in Section 5.7. The code is largely self-explanatory; however, we have included comments and additional explanations wherever necessary to enhance understanding.
Storing different types in a vector
#[derive(Debug)]enum Value { Integer(i32), Float(f32),}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: {}", num), } }}
Implementing a library management system
#[derive(Debug)]struct Item { id: i32, title: String, year: i32, type_: ItemType,}#[derive(Debug)]enum ItemType { Book, Magazine,}fn display_item_info(item: ...
Read now
Unlock full access