中級 › E0072: recursive type has infinite size の原因と直し方 › パターン5
E0072: recursive type has infinite size の原因と直し方
構造体が自分自身の型を直接フィールドに持つと、サイズが無限になってしまいコンパイルエラーになります。
1 struct Frame { 2 depth: i32, 3 parent: __________________, ^ 4 } 5 fn main() { 6 let n = Frame { depth: 1, parent: None }; 7 println!("{}", n.depth); 8 }
error[E0072]: recursive type `Frame` has infinite size
空欄を埋めて実行を通す
Box<Frame>はヒープ上のFrameへのポインタなので、Frame自体のサイズによらず一定サイズになります。
次の問題