Rust

[Rust lang] 86. box

밍글링글링 2023. 3. 30.
728x90
struct SomeStruct {
    name: String,
    number: u8,
    data: Box<[u8; 10000]>
}

fn main() {
    let my_struct = SomeStruct {
        name: "Hi there".to_string(),
        number: 0,
        data: Box::new([9; 1000])
    };

    let my_box = Box::new(9);

    println!("{my_box}");
    println!("{}", *my_box);
    println!("The struct is {} bytes", std::mem::size_of_val(&my_struct));
}
728x90

'Rust' 카테고리의 다른 글

[Rust lang] 88. three types of generics  (0) 2023.03.30
[Rust lang] 87. trait objects, box  (0) 2023.03.30
[Rust lang] 85. clippy  (0) 2023.03.30
[Rust lang] 84. mutex  (0) 2023.03.30
[Rust lang] 83. multiple threads  (0) 2023.03.30

댓글