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:
parent
eb7fe629ea
commit
7ce92303e9
@ -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)]
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user