projects
/
rust-101.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
7fdd420
)
Tune part 16
author
Ralf Jung
<post@ralfj.de>
Sun, 19 Jul 2015 11:02:09 +0000
(13:02 +0200)
committer
Ralf Jung
<post@ralfj.de>
Sun, 19 Jul 2015 11:02:09 +0000
(13:02 +0200)
src/part16.rs
patch
|
blob
|
history
workspace/src/part16.rs
patch
|
blob
|
history
diff --git
a/src/part16.rs
b/src/part16.rs
index fefccdf9d369ea514821065b3ea09539c46dafb2..5ae6a4824971b430984305301cd9c6732a03daee 100644
(file)
--- 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.
//@ 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
//@ 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 d0b173ab2e1a7e10faa5ff5f8337fadbcb4e7dca..835b8b85710a01e0bef3511b241c317410a25a16 100644
(file)
--- 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`
// Add testcases for both kinds of iterators.
// ## `Drop`
+
impl<T> Drop for LinkedList<T> {
// 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...
impl<T> Drop for LinkedList<T> {
// 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...