too-many-lists/ok-stack/type-optimizing #995
Replies: 5 comments 1 reply
-
也可以使用下面这种写法 let node = self.head.take()? |
Beta Was this translation helpful? Give feedback.
-
impl Drop for List{
fn drop(&mut self){
let mut cur_link = self.head.take();
while let Some(node) = cur_link {
// 获得node.next的所有权
cur_link = node.next;
// cur_link超出作用域,被释放
}
}
} 用这种方法实现Drop Trait可行吗? |
Beta Was this translation helpful? Give feedback.
-
感谢作者的开源工作! 前几篇读得我脑壳疼,我是把官方那些文档刷完来的,按理说技术还算过关。我读之前几篇的时候,看到结构体link,头疼,不知道为啥要这么搞。我觉得学rust肯定都是有编程经验的程序员,一个比较好的方法是,对比来学,链表在其他语言实现相对简单点,然后我们能不能按照既有的经验模式用rust写,中间会遇到很多问题,然后一个个解决,这种方法相对好一点。 |
Beta Was this translation helpful? Give feedback.
-
谢谢,看明白了。使用Option以后代码简洁了好多,赞! |
Beta Was this translation helpful? Give feedback.
-
Hi, i have received your email. Thanks!This is a auto-reply email.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
too-many-lists/ok-stack/type-optimizing
https://course.rs/too-many-lists/ok-stack/type-optimizing.html
Beta Was this translation helpful? Give feedback.
All reactions