Why do I get an error when pattern matching a struct-like enum variant with fields?

和自甴很熟 提交于 2019-12-05 10:38:13

Enum variants have three possible syntaxes:

  • unit

    enum A { One }
    
  • tuple

    enum B { Two(u8, bool) }
    
  • struct

    enum C { Three { a: f64, b: String } }
    

You have to use the same syntax when pattern matching as the syntax the variant was defined as.

In this case, you need curly braces and the .. catch-all:

OperationMode::CBC { .. } => {}

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!