繁体   English   中英

是否可以在 function 声明中解构具有无可辩驳的模式的元组?

[英]Is it possible to destructure a tuple with an irrefutable pattern in a function declaration?

在 rust 我目前可以做,

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

但我无法解构签名中的 arguments,

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

是否可以用无可辩驳的模式来解构一个元组?

你需要做的是输入整个元组而不是其中的组件,

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM