1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-02-18 09:40:22 +02:00

Clarify Default trait and operators (#717)

* Reword description of Default trait

* Clarify comparision to function type parameters

* Mention heterogenous types for operators
This commit is contained in:
Mauve 2023-05-29 12:09:09 -04:00 committed by GitHub
parent eb7fe629ea
commit 7ce92303e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,6 @@
# The `Default` Trait
[`Default`][1] trait provides a default implementation of a trait.
[`Default`][1] trait produces a default value for a type.
```rust,editable
#[derive(Debug, Default)]

View File

@ -30,10 +30,12 @@ Discussion points:
overloading the operator is not `Copy`, you should consider overloading
the operator for `&T` as well. This avoids unnecessary cloning on the
call site.
* Why is `Output` an associated type? Could it be made a type parameter?
* Short answer: Type parameters are controlled by the caller, but
* Why is `Output` an associated type? Could it be made a type parameter of the method?
* Short answer: Function type parameters are controlled by the caller, but
associated types (like `Output`) are controlled by the implementor of a
trait.
* You could implement `Add` for two different types, e.g.
`impl Add<(i32, i32)> for Point` would add a tuple to a `Point`.
</details>