You misunderstand. The vector and the borrow cannot be owned by the same thing. The main function will need two separate variables - one for holding the vector and one for holding the view.
Oh, ok. But, I have a situation where I need this behaviour. I want the data to be associated with the Builder and get cleaned up when the builder instance goes out of scope. In my real case, the data should be generated from builder and it has no knowledge of outer scope. Thanks
The underlying problem is that Rust structures can be relocated in memory, usually when the structure grows or shrinks in size. Self-referential addresses contained within such a structure become dangling pointers when such relocation occurs. However, indices are unaffected by relocation because the layout of the structure remains unchanged no matter where the structure is relocated in memory.