From: Ralf Jung Date: Tue, 21 Jul 2015 09:38:10 +0000 (+0200) Subject: tune explanation of PhantomData ownership annotation X-Git-Url: https://git.ralfj.de/rust-101.git/commitdiff_plain/ccf917e1f212cb8f8b07331ec60011f270621dd4?ds=sidebyside;hp=-c tune explanation of PhantomData ownership annotation --- ccf917e1f212cb8f8b07331ec60011f270621dd4 diff --git a/src/part16.rs b/src/part16.rs index 5ae6a48..eef6f0b 100644 --- a/src/part16.rs +++ b/src/part16.rs @@ -43,9 +43,9 @@ type NodePtr = *mut Node; // will own data of type `T`. //@ The type `PhantomData` does not actually store anything in memory - it has size zero. However, logically, //@ Rust will consider a `T` to be present. In this case, Rust knows that data of type `T` may be dropped -//@ whenever a `LinkedList` is dropped. The checks involving destructors are pretty subtle, so it's always -//@ a good idea to provide such extra information. In safe Rust, this can all be done automatically, but here, -//@ we just have a `*mut Node`, which Rust does not consider as actually owning the data it points to. +//@ whenever a `LinkedList` is dropped. Dropping has a lot of subtle checks to it, making sure that things can't go +//@ wrong. For this to work, Rust needs to know which types could potentially be dropped. In safe Rust, this can all be inferred +//@ automatically, but here, we just have a `*mut Node`, and we need to tell Rust that we actually own such data. pub struct LinkedList { first: NodePtr, last: NodePtr,