是否可以在函数声明中解构具有无可辩驳模式的元组?
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
}
但是我无法解构签名中的参数,
// 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
}
在 rust 中我目前可以做到,
// 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
}
是否可以用无可辩驳的模式解构元组?
您需要做的是键入整个元组而不是其中的组件,
// this function accepts (k,v) tuple
fn baz(
(k, v): (&str, u8) // notice the parens
) -> bool {
true
}