为什么我不能用声明元组的参数匹配的性状功能?

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

为什么我不能用声明元组的参数匹配的性状功能?

#![allow(unused)]

// This works
fn foo((x, y): (i32, i32)) {
}

trait Bar {
    // This does not work
    fn bar((x, y): (i32, i32));
}

Playground

编译上述输出该:

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`
syntax rust traits
1个回答
2
投票

这句法不生锈的支持,目前暂无开放的RFC来改变这种状况。

在一个特质,将成为不超过可能用于文档其他目的。但是,因为你是无论如何定义的特征,你可以只定义了一个更具描述性的类型,首先这样的说法。在你的情况下,Pointx字段y

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