小编Tyl*_*den的帖子

在编译器中对AST结构进行模式匹配

所以我试图在结构上进行模式匹配.这个特殊的结构由许多枚举构成,这些枚举包含指向枚举的指针,或者在最基本的层次上,是一个未签名的8字节向量.我想使用矢量,但是想知道是否可以模式匹配我的方式与vec.

ast::ExprUnary(ast::UnDeref, ref exprs) =>{
        let pat = match exprs.node {

            ast::ExprLit(ast::Lit(codemap::Spanned(ast::LitBinary(string),innerspan))) => {
                 //stuff to string
                 //primary issue here is that these enums, which ExprLit is 
                 //comprised of, do not pattern match correctly
            }
            _ => //other stuff
        };
Run Code Online (Sandbox Code Playgroud)

在编译此代码时,我收到以下两个错误,

unresolved enum variant, struct or const `Spanned`
unresolved enum variant, struct or const `Lit`
Run Code Online (Sandbox Code Playgroud)

这两个枚举都存在于ast中,但是,我不知道为什么它们在这个特定的上下文中是未解决的.任何意见,将不胜感激

pattern-matching rust

3
推荐指数
1
解决办法
367
查看次数

标签 统计

pattern-matching ×1

rust ×1