April 2026
Intermediate
631 pages
16h 20m
English
This section provides the code solutions for the practice exercises in Section 13.6. The code is largely self-explanatory; however, we have included comments and additional explanations wherever necessary to enhance understanding.
Fixing the size calculation of unsized types
use std::mem::size_of;fn main() { println!("[i32] size is: {}", size_of::<&[i32]>());}
Implementing correct handling of ?Sized trait bound in functions
fn some_fn<T: ?Sized + std::fmt::Debug>(val: &T) { println!("{:?}", val)}fn main() {}
Implementing generic structs with dynamically sized fields
struct FlexibleStruct<T: ?Sized> { fixed_part: u32, dynamic_part: T,}fn main() { let instance = FlexibleStruct { fixed_part: 42, dynamic_part: "Hello"
Read now
Unlock full access