April 2026
Intermediate
631 pages
16h 20m
English
This section provides the code solutions for the practice exercises in Section 8.4. The code is largely self-explanatory; however, we have included comments and additional explanations wherever necessary to enhance understanding.
Generic enum for basic mathematical operations
enum Operation<T> { Addition(T, T), Subtraction(T, T), Multiplication(T, T), Division(T, T),}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 op_4 = Operation::Division(2, 3);}
Fix the generic create method in the Container struct
struct Container<T> { value: T,}impl<T> Container<T> { fn new(value: T) -> Container<T> { /* we need to remove duplicate
Read now
Unlock full access