On 1/24/13 10:51 AM, Peter Ronnquist wrote:
Hi,
I am trying to create a vector of pointers into another vector without
much luck. I would be happy if someone could tell me if this a good way
to use rust or if there is a better way to achieve a similar data
structure or if I am using the wrong language :-)
I have a vector of physical objects:
obj_vec = [ mut @obj1, @obj2, @obj3, ..., @objn ]
I will iterate through those objects and see which ones are close to
each other and I want to store a pointer/reference to those objects in a
separate vector:
obj_close_vec = [ &obj2, &obj3 ]
The objects in obj_close_vec will be investigated further and might be
updated.
Does something like this work?
let mut obj_vec = [ @mut obj1, @mut obj2, ... @mut objn ];
let mut obj_close_vec: ~[@mut ObjType] = ~[];
for obj_vec.each |&obj| {
if obj.is_interesting() {
obj_close_vec.push(obj);
}
}
for obj_close_vec.each |&obj| {
if i_want_to_mutate(obj) {
*obj = munge(obj);
}
}
Patrick
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev