April 2026
Intermediate
631 pages
16h 20m
English
In this section, we’ll consider the size of a reference to an array and an array slice. Consider the code shown in Listing 13.4.
fn main() { println!( "Size of a reference to sized type: {}", size_of::<&[i32; 3]>() ); println!( "Size of a reference to unsized type: {}", size_of::<&[i32]>() );}
Listing 13.4 Displaying the Size of a Reference to an Array and Reference to an Array Slice
In the previous section, you learned that an array is a sized type, while an array slice is unsized. We also discussed how a simple reference is one machine word in size, which is typically 8 bytes on most machines. If you execute this code, you may notice the following output:
Size of a reference to sized type: 8Size of ...
Read now
Unlock full access