These are chat archives for rust-lang/rust

1st
Jan 2016
Grant Miner
@llambda
Jan 01 2016 20:11
Struggling with lifetimes; https://github.com/llambda/rreverse/blob/master/src/main.rs#L63 , I thought I could add my items to a vector and then pass the reference to the position in the vector to the kdtree, but the compiler says that cannot borrow vec as mutable because it is also borrowed as immutable
Peter Atashian
@retep998
Jan 01 2016 20:12
@llambda You're storing references to the elements in the vector in the kdtree, thus the vector is being borrowed
@llambda While something is borrowed, you cannot mutate it
@llambda Since a vector has a single contiguous buffer, when you're pushing elements it sometimes has to allocate a new larger buffer. When this happens all pointers to elements in that buffer become dangling pointers. Rust prevents this.
@llambda What you can do is first store all the items in the Vec, and then once that is done and you no longer need to modify the Vec, then you can shove references to the elements into your kdtree
Grant Miner
@llambda
Jan 01 2016 20:51
Oh ok..thanks @retep998 :)