diff --git a/src/traits/drop.md b/src/traits/drop.md index aa9cc2b0..2c5a5a22 100644 --- a/src/traits/drop.md +++ b/src/traits/drop.md @@ -28,3 +28,15 @@ fn main() { println!("Exiting main"); } ``` + +
+ +Discussion points: + +* Why does not `Drop::drop` take `self`? + * Short-answer: If it did, `std::mem::drop` would be called at the end of + the block, resulting in another call to `Drop::drop`, and a stack + overflow! +* Try replacing `drop(a)` with `a.drop()`. + +
\ No newline at end of file diff --git a/src/traits/operators.md b/src/traits/operators.md index b28bd9f8..8388178b 100644 --- a/src/traits/operators.md +++ b/src/traits/operators.md @@ -20,3 +20,19 @@ fn main() { println!("{:?} + {:?} = {:?}", p1, p2, p1 + p2); } ``` + +
+ +Discussion points: + +* You could implement `Add` for `&Point`. In which situations is that useful? + * Answer: `Add:add` consumes `self`. If type `T` for which you are + 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 + associated types (like `Output`) are controlled by the implementor of a + trait. + +
\ No newline at end of file