Я пытаюсь получить доступ к атрибуту штучной структуры внутри перечисления, но не могу понять, как сопоставить шаблон с std::boxed::Box
enum ArithExp {
Sum {
lhs: Box<ArithExp>,
rhs: Box<ArithExp>,
},
Mul {
lhs: Box<ArithExp>,
rhs: Box<ArithExp>,
},
Num {
value: f64,
},
}
fn num(value: f64) -> std::boxed::Box<ArithExp> {
Box::new(ArithExp::Num { value })
}
let mut number = num(1.0);
match number {
ArithExp::Num { value } => println!("VALUE = {}", value),
}
Я получаю следующую ошибку:
error[E0308]: mismatched types
--> src/main.rs:22:9
|
22 | ArithExp::Num { value } => println!("VALUE = {}", value),
| ^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `main::ArithExp`
|
= note: expected type `std::boxed::Box<main::ArithExp>`
found type `main::ArithExp`
Как правильно получить доступ к атрибуту?