From 174314786770835cff60100f9ea66aeec59745a4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 19 Jul 2015 13:02:09 +0200 Subject: [PATCH] Tune part 16 --- src/part16.rs | 2 +- workspace/src/part16.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/part16.rs b/src/part16.rs index fefccdf..5ae6a48 100644 --- a/src/part16.rs +++ b/src/part16.rs @@ -166,7 +166,7 @@ impl<'a, T> Iterator for IterMut<'a, T> { //@ The linked list we wrote is already working quite nicely, but there is one problem: When the list is dropped, //@ nobody bothers to deallocate the remaining nodes. Even worse, if `T` itself has a destructor that needs to //@ clean up, it is not called for the element remaining in the list. We need to take care of that ourselves. -//@ + //@ In Rust, adding a destructor for a type is done by implementing the `Drop` trait. This is a very special trait. //@ It can only be implemented for *nominal types*, i.e., you cannot implement `Drop` for `&mut T`. You also cannot //@ restrict the type and lifetime parameters further than the type does - the `Drop` implementation has to apply to *all* instances diff --git a/workspace/src/part16.rs b/workspace/src/part16.rs index d0b173a..835b8b8 100644 --- a/workspace/src/part16.rs +++ b/workspace/src/part16.rs @@ -94,6 +94,7 @@ impl<'a, T> Iterator for IterMut<'a, T> { // Add testcases for both kinds of iterators. // ## `Drop` + impl Drop for LinkedList { // The destructor itself is a method which takes `self` in mutably borrowed form. It cannot own `self`, because then // the destructor of `self` would be called at the end pf the function, resulting in endless recursion... -- 2.30.2