So I have a struct looking like this:
struct InterpolationList<'a, T: Interpolatable<T, Output=T>> {,
first_entry: InterpolationListValue<'a, T>,
last_entry: &'a mut InterpolationListValue<'a, T>,
}
And now I implemented a new
function to create a simple "Instance":
pub fn new(distance: u64, value: T) -> InterpolationList<'a, T> {
let mut initial_entry = InterpolationListValue::new(distance, value);
InterpolationList {
first_entry: initial_entry,
last_entry: &mut initial_entry,
}
}
This however gives me the following errors:
cannot return value referencing local variable `initial_entry`
/ InterpolationList {
20 | | first_entry: initial_entry,
21 | | last_entry: &mut initial_entry,
| | ------------------ `initial_entry` is borrowed here
23 | | }
| |_________^ returns a value referencing data owned by the current function
borrow of moved value: `initial_entry`
|
17 | let mut initial_entry = InterpolationListValue::new(distance, value);
| ----------------- move occurs because `initial_entry` has type `InterpolationListValue<'_, T>`, which does not implement the `Copy` trait
...
23 | first_entry: initial_entry,
| ------------- value moved here
24 | last_entry: &mut initial_entry,
| ^^^^^^^^^^^^^^^^^^ value borrowed here after move
My guess is that rust thinks, ownership of initial_entry still belongs to the function, even though it is moved to the InterpolationList
struct, because both move and referencing happens in the same instruction.
Does anybody know how to fix/circumvent this?