Skip to content

Bug in documentation #1628

Closed
rust-lang/rust
#103543
@Abhicodes-crypto

Description

@Abhicodes-crypto

I was reading about Box from here https://doc.rust-lang.org/stable/rust-by-example/std/box.html
There is the below code in code snippet :

    // box size == pointer size
    println!("Boxed point occupies {} bytes on the heap",
             mem::size_of_val(&boxed_point));
    println!("Boxed rectangle occupies {} bytes on the heap",
             mem::size_of_val(&boxed_rectangle));
    println!("Boxed box occupies {} bytes on the heap",
             mem::size_of_val(&box_in_a_box));

I increased the variables in Point struct and mades its size 40 bytes on stack but still the Box size is 8 bytes , so in this code . I think the statements should be Boxed point occupies {} bytes on the stack instead of the heap. Basically I am saying that Box is holding an address value of the actual structure and the size of box is 8 bytes which is fixed.

If this is right , can I raise a PR with the Fix ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions