Avatar ·

What is a "fat pointer" in Rust and how is it different from a regular one?

Hello, colleagues! I started learning Rust and came across the term "fat pointer". Books say it's "a pointer with additional metadata", but I can't understand why it's needed and where it's used.\n\nI know that Rust has regular references `&T` that simply point to data. But for example, slices. I wrote this code:\n\n```rust\nfn main() {\n let arr = [1, 2, 3, 4, 5];\n let slice: &[i32] = &arr[1..4];\n println!("Slice length: {}", slice.len()); // Will print 3\n}\n```\n\nI don't understand: how does Rust know that the slice length is 3 if I only pass a reference to the first element? A regular pointer in C/C++ only stores an address, and the length needs to be passed separately. So, is `&[i32]` not just an address?\n\nI've also heard about trait objects, like