1 // SPDX-License-Identifier: Apache-2.0 OR MIT
2
3 use pin_init::*;
4
5 // Struct with size over 1GiB
6 #[derive(Debug)]
7 pub struct BigStruct {
8 buf: [u8; 1024 * 1024 * 1024],
9 a: u64,
10 b: u64,
11 c: u64,
12 d: u64,
13 managed_buf: ManagedBuf,
14 }
15
16 #[derive(Debug)]
17 pub struct ManagedBuf {
18 buf: [u8; 1024 * 1024],
19 }
20
21 impl ManagedBuf {
new() -> impl Init<Self>22 pub fn new() -> impl Init<Self> {
23 init!(ManagedBuf { buf <- zeroed() })
24 }
25 }
26
main()27 fn main() {
28 // we want to initialize the struct in-place, otherwise we would get a stackoverflow
29 let buf: Box<BigStruct> = Box::init(init!(BigStruct {
30 buf <- zeroed(),
31 a: 7,
32 b: 186,
33 c: 7789,
34 d: 34,
35 managed_buf <- ManagedBuf::new(),
36 }))
37 .unwrap();
38 println!("{}", core::mem::size_of_val(&*buf));
39 }
40