too-many-lists/bad-stack/layout #898
Replies: 6 comments 12 replies
-
pub enum List { |
Beta Was this translation helpful? Give feedback.
-
那个null指针优化用Option也可以做: pub struct List {
head: Link,
}
enum Link {
Empty,
More(Box<Node>),
}
struct Node {
elem: i32,
next: Link,
} 换成 pub struct List {
head: Option<Box<Node>>,
}
struct Node {
elem: i32,
next: Option<Box<Node>>,
}
use std::mem::size_of;
assert_eq!(size_of::<Option<Box<Node>>>(), size_of::<Box<Node>>()); 这个断言亲测可以过 |
Beta Was this translation helpful? Give feedback.
-
pub struct Node{
elem: i32,
next: List,
}
enum List{
Empty,
More(Box<Node>)
} 我这里没有报error |
Beta Was this translation helpful? Give feedback.
-
为什么开头需要举例一个 |
Beta Was this translation helpful? Give feedback.
-
直接看这个给我看懵了 |
Beta Was this translation helpful? Give feedback.
-
感觉这个Link可以拿Option代替 struct Node {
elem: i32,
next: Option<Box<Node>>,
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
too-many-lists/bad-stack/layout
https://course.rs/too-many-lists/bad-stack/layout.html
Beta Was this translation helpful? Give feedback.
All reactions