Is it impossible to have a nested match on a recursive datatype that uses a smart pointer like a Box, Rc, or Arc?

Solution 1:

It appears that yes, it is currently impossible to do this. Recursive datatypes require indirection, e.g. Rc. Indirection requires dereferences when matching against nested patterns. There is no way to dereference inside a pattern match in Rust today.

The workaround is to compile your patterns by hand, i.e. as if you only had C-style switch.

A feature called "box patterns" has been discussed since 2014 that may solve this problem in the future but it hasn't shipped.