-
Notifications
You must be signed in to change notification settings - Fork 296
Open
Description
This code is unfortunately completely misleading:
pub fn push(&mut self, elem: T) <here is no return code mentioned> {
let new_tail = Box::new(Node { new_tail is holding the Box
elem: elem,
// When you push onto the tail, your next is always None
next: None,
});
// Put the box in the right place, and then grab a reference to its Node
let new_tail = match self.tail.take() { new_tail is now something complete different and the Box is dropped
Some(old_tail) => {
// If the old tail existed, update it to point to the new tail
old_tail.next = Some(new_tail);
old_tail.next.as_deref_mut() <- but this is returning a mut reference
}
None => {
// Otherwise, update the head to point to it
self.head = Some(new_tail);
self.head.as_deref_mut() < - and this returns also a mut reference
}
Is push() in this intermediate version meant to return something and is new_tail holding the box until it is linked and has a new owner?
Metadata
Metadata
Assignees
Labels
No labels