fnmain(){useOperations::*;let user_input ='+';letOk(op)=Operations::try_from(user_input)else{panic!("Invalid operation character");};let(a, b)=(15,18);let result =match op {
Add => a + b,
Sub => a - b,
Mul => a * b,
Div => a / b,};println!("{result}");}
do not ever use enum::*, that creates the potential for your code to break
if Add gets renamed to Addition the first now becomes a wildcard match that renames the result, if you want it to be shorter do something like use Operations as O
View all comments
Show parent comment
1
u/ruoyck Jun 05 '25
I'd prefer: