Looping through the indexes (i.e. for idx in 0..graph.adjancy_list.len() { ... }) should be the easiest way but it may not be the fastest since the bound checks may not be elided by the compiler. It's probably faster than cloning though.
IMO for now the split_first_mut solution is the most idiomatic solution. This problem could be easily solved in a more elegant way if we had streaming iterators, however a good generic abstraction for them requires features that aren't stable yet.
for i in 0..graph.adjancy_list.len(){
let mut n = graph.adjancy_list[i].clone();
for ii in 0..graph.adjancy_list.len(){
let nn = &graph.adjancy_list[ii];
let dif = (n.position.0 - nn.position.0, n.position.1 - nn.position.1);
let norm : usize = (((dif.0*dif.0) + (dif.1*dif.1)) as f64).sqrt() as usize;
let factor = repulsion(norm) / ( norm as f64);
n.position.0 *= factor;
n.position.1 *= factor;
}
}
looks greate to me, i'll try refactor using split_first_mut once my program works, thx all problem solved