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

后端 未结 1 1577
名媛妹妹
名媛妹妹 2020-12-21 05:16

I\'m trying to port this program that computes the nth derivative of x^x symbolically to Rust. It seems to be mostly easy:

use std::rc::Rc;

typ         


        
相关标签:
1条回答
  • 2020-12-21 05:47

    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.

    0 讨论(0)
提交回复
热议问题