Skip to content

Commit

Permalink
Merge pull request #85 from weliu/main
Browse files Browse the repository at this point in the history
Update item10-std-traits.md
  • Loading branch information
lispking authored Nov 15, 2024
2 parents b3a5628 + d6f6bb6 commit e42e0ce
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/chapter_2/item10-std-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ println!("k = {k:?}");
在这方面,这跟 C++ 的拷贝构造函数又有相似了,但是值得强调的一个关键区别在于:在 Rust 里面没有办法让编译器隐式调用用户定义的代码——要调用的话必须显式指定(比如使用 `.clone()`),或者让编译器执行并非由用户定义的代码(按比特位的拷贝动作)。
因为 `Copy` 具有 `Clone` trait 的特性,所以是可以 `.clone()` 任意一个满足 `Copy` 的对象的。但是这不是一个好的主义:按位拷贝总是会比调用 trait 方法要快。Clippy([第 29 条])会提示你:
因为 `Copy` 具有 `Clone` trait 的特性,所以是可以 `.clone()` 任意一个满足 `Copy` 的对象的。但是这不是一个好的主意:按位拷贝总是会比调用 trait 方法要快。Clippy([第 29 条])会提示你:
```rust
let k3 = k.clone();
Expand Down Expand Up @@ -500,4 +500,4 @@ if x <= y {
[try_from]:https://doc.rust-lang.org/std/convert/trait.TryFrom.html#tymethod.try_from
[try_into]:https://doc.rust-lang.org/std/convert/trait.TryInto.html#tymethod.try_into
[TryFrom]:https://doc.rust-lang.org/std/convert/trait.TryFrom.html
[TryInto]:https://doc.rust-lang.org/std/convert/trait.TryInto.html
[TryInto]:https://doc.rust-lang.org/std/convert/trait.TryInto.html

0 comments on commit e42e0ce

Please sign in to comment.