Path for a reference to a vec's item?

⚓ rust    📅 2025-05-08    👤 surdeus    👁️ 6      

surdeus

Warning

This post was published 54 days ago. The information described in this article may have changed.

In this code:

fn main() {
    let a: Vec<i32> = vec![1,2,3];
    let b: &i32 = &a[2];
    println!("{a:?}, {b}");
}

Should I think of b as path number 2 in the image below, or paths number 1a and 1b (although in this case I'm unsure how it directs to 1b unless it remembers the offset, somehow ?

Screenshot from 2025-05-08 14-29-06

If you want to edit the image maybe this can be forked from the source.

5 posts - 2 participants

Read full topic

🏷️ rust_feed