Can somebody help me with unboxing:
enum List <'a> {
Cons(i32, &'a Box<List<'a>>),
Nil,
}
use List::{Cons, Nil};
fn main() {
let nil = Box::new(Nil);
let l10 = Box::new(Cons(10, &nil));
if let Cons(n, _) = l10 {
println!("{:?}", n);
}
}
> src/main.rs:11:12

11  if let Cons(n, _) = l10 {
 ^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `List`

= note: expected type `std::boxed::Box<List<'_>>`
found type `List<'_>`
Is there a way to extract Cons
(or any other enum
) out of Box
with stable Rust (I'm aware of box
keyword, it's not in stable yet)?
if let Cons(n, _) = *l10
?
if let
(not in this code) where, as I see now, I have to use **tail
as the first match Cons(n, tail)
returns a reference to Box
.