too-many-lists/bad-stack/layout #898
Replies: 5 comments 11 replies
-
pub enum List { |
Beta Was this translation helpful? Give feedback.
5 replies
-
那个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.
2 replies
-
pub struct Node{
elem: i32,
next: List,
}
enum List{
Empty,
More(Box<Node>)
} 我这里没有报error |
Beta Was this translation helpful? Give feedback.
1 reply
-
为什么开头需要举例一个 |
Beta Was this translation helpful? Give feedback.
3 replies
-
直接看这个给我看懵了 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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