Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update trait.md #1328

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/basic/trait/trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ sunface发表了微博好像微博没Tweet好用

#### 默认实现

你可以在特征中定义具有**默认实现**的方法,这样其它类型无需再实现该方法,或者也可以选择重载该方法
你可以在特征中定义具有**默认实现**的方法,这样其它类型无需再实现该方法,或者也可以选择重写该方法

```rust
pub trait Summary {
Expand All @@ -125,7 +125,7 @@ impl Summary for Weibo {
}
```

可以看到,`Post` 选择了默认实现,而 `Weibo` 重载了该方法,调用和输出如下:
可以看到,`Post` 选择了默认实现,而 `Weibo` 重写了该方法,调用和输出如下:

```rust
println!("{}",post.summarize());
Expand Down Expand Up @@ -432,7 +432,7 @@ fn main() {

再如 `Copy` 特征,它也有一套自动实现的默认代码,当标记到一个类型上时,可以让这个类型自动实现 `Copy` 特征,进而可以调用 `copy` 方法,进行自我复制。

总之,`derive` 派生出来的是 Rust 默认给我们提供的特征,在开发过程中极大的简化了自己手动实现相应特征的需求,当然,如果你有特殊的需求,还可以自己手动重载该实现
总之,`derive` 派生出来的是 Rust 默认给我们提供的特征,在开发过程中极大的简化了自己手动实现相应特征的需求,当然,如果你有特殊的需求,还可以自己手动重写该实现

详细的 `derive` 列表参见[附录-派生特征](https://course.rs/appendix/derive.html)。

Expand Down