[英]Is it possible to destructure a tuple with an irrefutable pattern in a function declaration?
In rust I can currently do,在 rust 我目前可以做,
// this function accepts k,v
fn foo(
k: &str, v: u8
) -> bool {
true
}
But I can not destructure the arguments in the signature,但我无法解构签名中的 arguments,
// this function accepts (k,v) tuple
fn bar(
(k: &str, v: u8) // notice the parens
) -> bool {
true
}
Is it possible to destructure a tuple with an irrefutable pattern?是否可以用无可辩驳的模式来解构一个元组?
What you have to do is type the whole tuple not the components inside it,你需要做的是输入整个元组而不是其中的组件,
// 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.