You should be able to fix it like this (something you called "satisfy the borrow checker"):
fn add_raw(&mut self, pair: RawLinkPair) {
let (parent, child) = {
let convert = |raw: RawLink| {
Link{
id: self.get_or_create(raw.name).id,
flow: raw.flow,
}
};
(convert(pair.parent.clone()), convert(pair.child.clone()))
};
self.link_concepts(parent, child);
}
As far as I know, this is something inexpressible in current Rust directly (i.e. without closures). Closures take their environment through &only
reference (currently it is only available to compiler), which forbids taking other references until it goes out of scope. It is like &mut
reference but not necessarily tied to mutability. Closure environment capture happens upon its creation, so lifetime of this capture extends to the end of the function, hence you're getting the error.
Why closures should take their environment by unique reference I don't know, though.