mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-02 23:38:41 +08:00
Update src/ch10-02-traits.md
This commit is contained in:
parent
8965bfdd86
commit
79440265c6
@ -184,7 +184,7 @@ pub fn notify(item: impl Summary) {
|
|||||||
|
|
||||||
#### Trait Bound 语法
|
#### Trait Bound 语法
|
||||||
|
|
||||||
`impl Trait` 语法适用于直观的例子,它不过是一个较长形式的语法糖。这被称为 *trait bound*,这看起来像:
|
`impl Trait` 语法适用于直观的例子,它实际上是一种较长形式语法的语法糖。我们称为 *trait bound*,它看起来像:
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
pub fn notify<T: Summary>(item: T) {
|
pub fn notify<T: Summary>(item: T) {
|
||||||
@ -241,7 +241,7 @@ fn some_function<T, U>(t: T, u: U) -> i32
|
|||||||
{
|
{
|
||||||
```
|
```
|
||||||
|
|
||||||
这个函数签名就显得不那么杂乱,函数名、参数列表和返回值类型都离得很近,看起来类似没有很多 trait bounds 的函数。
|
这个函数签名就显得不那么杂乱,函数名、参数列表和返回值类型都离得很近,看起来跟没有那么多 trait bounds 的函数很像。
|
||||||
|
|
||||||
### 返回实现了 trait 的类型
|
### 返回实现了 trait 的类型
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user