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 8.5.
Generic enum for basic mathematical operationsConsider the following code in main. Write a generic enum named Operation that makes the code in main compile. The generic enum should represent the four basic mathematical operations: addition, subtraction, multiplication, and division. Each variant of the enum should store two values of the same type.
fn main() { let op_1 = Operation::Addition(5, 10); let op_2 = Operation::Multiplication(3.5, 2.0); let op_3 = Operation::Subtraction(3.5, 2.0); let
Read now
Unlock full access