X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/a7fde6ca45fecd14ac7764f47d74a76bb8853352..1f6a5ed7a44ed00827fd3312503f20b8f52f94db:/src/part16.rs diff --git a/src/part16.rs b/src/part16.rs index c02959d..22c912a 100644 --- a/src/part16.rs +++ b/src/part16.rs @@ -55,7 +55,8 @@ pub struct LinkedList { //@ Before we get to the actual linked-list methods, we write two short helper functions converting between mutable raw pointers, //@ and boxed data. Both employ `mem::transmute`, which can convert anything to anything, by just re-interpreting the bytes. -//@ Clearly, that's an unsafe operation and must only be used with great care - or even better, not at all.
+//@ Clearly, that's an unsafe operation and must only be used with great care - or even better, not at all. Seriously. +//@ If at all possible, you should never use `transmute`.
//@ We are making the assumption here that a `Box` and a raw pointer have the same representation in memory. In the future, //@ Rust will [provide](http://doc.rust-lang.org/beta/alloc/boxed/struct.Box.html#method.from_raw) such [operations](http://doc.rust-lang.org/beta/alloc/boxed/struct.Box.html#method.into_raw) in the standard library, but the exact API is still being fleshed out. @@ -80,8 +81,7 @@ impl LinkedList { // This function adds a new node to the end of the list. pub fn push_back(&mut self, t: T) { // Create the new node, and make it a raw pointer. - //@ Calling `box_into_raw` gives up ownership of the box, which is crucial: We don't want the - //@ memory that it points to to be deallocated! + //@ Calling `box_into_raw` gives up ownership of the box, which is crucial: We don't want the memory that it points to to be deallocated! let new = Box::new( Node { data: t, next: ptr::null_mut(), prev: self.last } ); let new = box_into_raw(new); // Update other points to this node.