Hi,
I have two functions that I am trying to combine to one function. I am struggling with borrow/movement concept. Can I combine calc_prc and calc_prc2? The calling function is calling calc_prc and calc_prc2 with the same df_rows vector.
pub fn build_df(res:&mut Vec<crate::dbhandling::Res1>)
{
let mut df_rows = Vec::new();
let mut prices = Vec::new();
copy_data_df(res, &mut df_rows, &mut prices);
calc_prc(&mut df_rows, &mut prices);
calc_prc2(&mut df_rows);
}
fn calc_prc(df_rows: &mut Vec<Dfrow>, prices: &mut Vec<f64>)
{
let mut i = 0;
for d in df_rows
{
if i == 0
{
i += 1;
continue;
}
d.back_prc[0] = prc(prices[i], prices[i-1]);
i += 1;
}
}
fn calc_prc2(df_rows2: &mut Vec<Dfrow>)
{
let num_entries = df_rows2.len();
for t in 1..100
{
for i in t..num_entries
{
df_rows2[i].back_prc[t] = df_rows2[i-1].back_prc[t-1];
}
}
}
fn prc(newdata:f64, old:f64) -> f64
{
return 100000.0 * (newdata - old) / old;
}
Thanks,
Mor