为什么我不能用声明元组的参数匹配的性状功能?
#![allow(unused)]
// This works
fn foo((x, y): (i32, i32)) {
}
trait Bar {
// This does not work
fn bar((x, y): (i32, i32));
}
编译上述输出该:
error: expected one of `)` or `,`, found `:`
--> src/main.rs:7:18
|
7 | fn bar((x, y): (i32, i32));
| ^ expected one of `)` or `,` here
error: expected one of `!`, `&&`, `&`, `(`, `)`, `*`, `<`, `?`, `[`, `_`, `dyn`, `extern`, `fn`, `for`, `impl`, `unsafe`, or lifetime, found `:`
--> src/main.rs:7:18
|
7 | fn bar((x, y): (i32, i32));
| ^ expected one of 17 possible tokens here
error[E0601]: `main` function not found in crate `playground`
|
= note: consider adding a `main` function to `src/main.rs`
这句法不生锈的支持,目前暂无开放的RFC来改变这种状况。
在一个特质,将成为不超过可能用于文档其他目的。但是,因为你是无论如何定义的特征,你可以只定义了一个更具描述性的类型,首先这样的说法。在你的情况下,Point
和x
字段y
。