too-many-lists/persistent-stack/drop-arc #1059
Replies: 4 comments 7 replies
-
impl<T> Drop for List<T> {
fn drop(&mut self) {
while let Some(node) = self.head.take() {
match Rc::try_unwrap(node) {
Ok(mut n) => {
self.head = n.next.take();
}
_ => (),
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
这里对于Drop Trait有点疑问, 本地测试的时候, 如果Rc List不实现Drop Trait, 实际上并不会像Box List产生stack overflow的问题, |
Beta Was this translation helpful? Give feedback.
-
请问一下大佬, 为什么 self.head.take()没有错误, 而 boxed_node.next.take()会报错,两者同样是有Rc持有啊? |
Beta Was this translation helpful? Give feedback.
-
把take换成clone应该没问题。。
|
Beta Was this translation helpful? Give feedback.
-
too-many-lists/persistent-stack/drop-arc
https://course.rs/too-many-lists/persistent-stack/drop-arc.html
Beta Was this translation helpful? Give feedback.
All reactions