Struct 建议用什么方法来分解嵌套选项?
如何读取嵌套在两个Struct 建议用什么方法来分解嵌套选项?,struct,rust,optional,destructuring,Struct,Rust,Optional,Destructuring,如何读取嵌套在两个选项中的值 我有以下代码: struct-Person{ 名称:&'static str, 首选项:Vecif-let-Some(Some(x))=…或其他嵌套模式有时也很有用。将重复项应用于这种情况:if-let-Some(Person{variant:Some(driver),…})=found也可以使用if-let-Some(driver)=found and_-then(|p | p.variant.as_ref())Ah@Shepmaster,你的第一条评论是先解构P
选项中的值
我有以下代码:
struct-Person{
名称:&'static str,
首选项:Vecif-let-Some(Some(x))=…
或其他嵌套模式有时也很有用。将重复项应用于这种情况:if-let-Some(Person{variant:Some(driver),…})=found
也可以使用if-let-Some(driver)=found and_-then(|p | p.variant.as_ref())
Ah@Shepmaster,你的第一条评论是先解构Person
struct,然后再解构字段variant
,似乎可以解决问题!没有编译错误。我尝试过一些变体,但我想我到现在为止还没有找到正确的语法!谢谢!