是否可以用不可辩驳的模式来破坏元组?

问题描述 投票:0回答:1

我目前可以做的锈病,

// this function accepts k,v
fn foo(
    k: &str, v: u8
) -> bool {
    true
}

但是我不能破坏签名中的参数,

// this function accepts (k,v) tuple
fn bar(
    (k: &str, v: u8) // notice the parens
) -> bool {
    true
}

是否可以用不可辩驳的模式破坏元组?

rust tuples pattern-matching destructuring
1个回答
0
投票
您要做的是键入整个元组而不是其中的组件,

// this function accepts (k,v) tuple fn baz( (k: &str, v: u8) // notice the parens ) -> bool { true }

© www.soinside.com 2019 - 2024. All rights reserved.